views:

44

answers:

1

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?

+1  A: 

The connection closes after the sproc is complete. This is built into Sobsonic 2.

WVDominick
Great, but how can I verify that it is in fact closed, and close it if not?
ElHaix