ado.net 事务已回滚,没有任何 .net 错误

ado.net transaction rollbacked without any .net error

事务有时会回滚,即使代码中没有错误。

当 dbconnectin 丢失或失败时,ado.net 会回滚吗?它只偶尔发生在特定的机器上。

  using (var dbTransactionManager = new DBTransactionManager())
        {
            try
            {

               //Insert statatement 1

               //Insert statatement 1 //after this statement, transaction is rollbacked, rest of the below statements run without transaction. this doesn't happen always.


               //Insert statatement 1

               //Insert statatement 1

               //Insert statatement 1




                dbTransactionManager.Commit();
                transactionClosed = true;
            }
            catch
            {
                //this never called.
                if (transactionClosed == false)
                {    
                    dbTransactionManager.RollBack();
                }

                throw;
            }
        }

是 ADO.NET 如果连接为空,则正在执行回滚。正如 jdweng 在他的评论中指出的那样,在交易的 dispose 方法中执行测试以检查是否 connection == null。如果是null,则进行事务回滚