SubSonic - 是否有必要/如何显式关闭数据库连接?

时间:2010-03-02 03:30:46

标签: database-connection subsonic

传统上,当从sproc中检索数据时使用DbCommand时,类似以下内容是一种很好的做法:

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();
        }
    }
}

现在,给定以下类型的SubSonic呼叫:

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)
{
...
}

如何明确确保数据库连接已关闭?

1 个答案:

答案 0 :(得分:1)

sproc完成后连接关闭。这是Sobsonic 2的内置。

相关问题