Traditionally when using a DbCommand when retrieving data from a sproc, something like the following is good practice:
DbCommand cmdDbCommand...
dbGetData = DatabaseFactory.CreateDatabase("MyDatabase");
cmdDbCommand = dbGetData.GetStoredProcCommand("MySproc");
.
.
.
try
{
...
}
catch (System.Exception ex)
{
if (cmdDbCommandcmdDbCommand != null)
{
if (cmdDbCommand.Connection.State == ConnectionState.Open)
{
cmdDbCommand.Connection.Close();
cmdDbCommand.Dispose();
}
}
}
Now, given the following type of SubSonic call:
try
{
StoredProcedure sp = SPs.GetSprocData(someID, result, errorMessage);
dsResults = sp.GetDataSet();
intResGetUserDetails = (int)sp.OutputValues[0];
errorMessage = (string)sp.OutputValues[1];
}
catch (System.Exception ex)
{
...
}
How can I explicitly ensure that the database connection has been closed?