我正在使用Database.ExecuteNonQuery执行具有 OUTPUT 参数的过程,并希望知道如何关闭此连接。我不能使用using块,因为 Database 类没有实现 IDisposable。在 Database 类中,还有一个名为ConnectionWrapper的类,如下所示:
protected class ConnectionWrapper : IDisposable
{
public ConnectionWrapper(DbConnection connection, bool disposeConnection);
public DbConnection Connection { get; }
public void Dispose();
}
我可以使用这个类来关闭连接吗?
我没有使用 DataReader。我正在使用Database.GetParameterValue从过程中获取结果。
我正在使用的一些代码:
Database db = DatabaseFactory.CreateDatabase("DatabaseConnectionString");
DbCommand command = db.GetStoredProcCommand("StoredProcName");
// Setting the parameters
db.AddInParameter(command, "@login", DbType.String, "value");
db.AddOutParameter(command, "@IdUser", DbType.Decimal, 10);
db.ExecuteNonQuery(command);
// Getting the values from the procedure
int idUser = int.Parse(db.GetParameterValue(command, "@IdUser").ToString());