I am using .NET 2.0 along with Data Access Application Block of
Enterprise Library 2.0 in one of my wrapper class and what I observered
is once the connection is left open after execution of ExecuteDataSet
function of Database class.
I used Preformance counter for SQL user connection. When
DataFactroy.CreateDatabase is executed it create a connection but when
Database.ExecuteDataset doesn't closes the connection. Furthermore, if
I close by application then connection is also closed and I can see the
count going down by 1 in the Performace counter. This doesn't happen
when ExecuteDataSet is called.
Following is the code snippet I am using in my wrapper class.
private DataSet ExecuteSp(string storedProc)
{
Database db = DatabaseFactroy.CreateConnection();
DbCommand dbCommand = db.GetStoredProcCommand("any_sp");
//Set the parameter in the command object
db.AddInParameter(dbCommand, "Param1", DbType.String,
"Param_val");
//Execute the sp and generate the dataset
DataSet dataSet;
using (dataSet = db.ExecuteDataSet(dbCommand))
//reset the variables
dbParameter = null;
dbCommand = null;
db = null;
//return dataset
return dataSet;
}
According to documents, ExecuteDataSet closes the connection but as per
my observation on Performace counter it isn't
Does anyone have any idea on how to close the connection once created
by DataFactory.CreateDatabase()?