事务,即使代码没有错误。
当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;
}
}
答案 0 :(得分:0)
是的,如果连接为空,则ADO.NET将执行回滚。正如jdweng在其评论中指出的那样,在事务的dispose
方法中,将执行测试以检查是否connection == null
。如果为null
,将执行事务回滚。