DbDataReader with DbTransactions

Posted by Gustavo Paulillo on Stack Overflow See other posts from Stack Overflow or by Gustavo Paulillo
Published on 2010-04-14T12:08:26Z Indexed on 2010/04/14 12:13 UTC
Read the original article Hit count: 425

Filed under:
|
|
|

Its the wrong way or lack of performance, using DbDataReader combinated with DbTransactions? An example of code:

public DbDataReader ExecuteReader()
    {
        try
        {
            if (this._baseConnection.State == ConnectionState.Closed)
                this._baseConnection.Open();
            if (this._baseCommand.Transaction != null)
                return this._baseCommand.ExecuteReader();
            return this._baseCommand.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (Exception excp)
        {
            if (this._baseCommand.Transaction != null)
                this._baseCommand.Transaction.Rollback();
            this._baseCommand.CommandText = string.Empty;
            this._baseConnection.Close();
            throw new Exception(excp.Message);
        }
    }

Some methods call this operation. Sometimes openning a DbTransaction. Its using DbConnection and DbCommand.

The real problem, is in production enviroment (like 5,000 access/day) the ADO operations start throwing exceptions

© Stack Overflow or respective owner

Related posts about .NET

Related posts about database