如何检查Dotnet事务是否回滚?

如何检查dotnet交易是否已关闭?     
已邀请:
using(TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)){

    try{
        //Do something;

        scope.Complete();  //denotes the transaction completed successful.
    }
    catch(TransactionAbortedException ex)
    {

        //scope.Complete(); is never called, the transaction rolls back automatically.
    }
    catch(ApplicationException ex)
    {

    }
}
    
你的标题会问一件事,你的问题会问另一件事。所以,我想要你的头衔。 如果您想知道事务是否已回滚或仅设置为回滚,则可以检查
transaction.WasRolledBack // true if transaction is rolled back
在这里,
transaction
是ITransaction的一个实例 编辑(根据您的评论):
var isRolledBack = false;
using (var connection = new SqlConnection())
{
  using (var transaction = connection.BeginTransaction())
  {
    try
    {
      // do your stuff here with transaction
    }
    catch (Exception ex)
    {
      transaction.Rollback();
      isRolledBack = true;
      throw;
    }
  }
}
现在,您可以检查ѭ​​4ѭ标志以查看事务是否已回滚     
如果您在SQL服务器上,则可以使用
DBCC OPENTRAN
http://msdn.microsoft.com/en-us/library/ms182792.aspx     

要回复问题请先登录注册