This OdbcTransaction has completed; it is no longer usable.
I got this exception when I was trying to perform multiple row insert in a DB2 database using Enterprise Library 5.0 and DbTransaction.
Cause of this exception:
I was trying to invoke ExecuteNonQuery method from Database object instead of DbCommand object. And, when one of the SQL failed (due to syntax or data problem), the catch block caught the exception and tried to rollback but DbTransaction.Rollback failed and it was throwing the above exception.
In order to solve this issue, set the transaction object in DBCommand.Transaction property and ExecuteNonQuery in DbCommand. Plus, the connection should be in open state when trying to rollback. The working code sample is given below,
internal static bool InsertRecords(List<string> sqlCollection)
Database database = DatabaseFactory.CreateDatabase(Utility.GetDB2ConnectionName);
using (DbConnection dbConnection = database.CreateConnection())
DbCommand dbCommand = dbConnection.CreateCommand();
DbTransaction dbTransaction = null;
dbTransaction = dbConnection.BeginTransaction();
dbCommand.Transaction = dbTransaction;
foreach (string sql in sqlCollection)
dbCommand.CommandText = sql;
dbCommand.CommandType = CommandType.Text;
catch (Exception error)
if (dbTransaction != null)
No comments yet.