SubSonic - Is it necessary to/how to explicitly close the database connection?
Traditionally when using开发者_StackOverflow中文版 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?
The connection closes after the sproc is complete. This is built into Sobsonic 2.
精彩评论