使用IEnlistmentNotification接口进行两阶段提交

时间:2010-06-07 17:54:59

标签: c# transactions transactionscope

调用Commit时(为了实现IEnlistmentNotification)我可以抛出一个异常来表示我希望事务回滚吗?

1 个答案:

答案 0 :(得分:0)

您应该致电Transaction.Rollback(Exception ex)

   public void Commit(Enlistment enlistment)
   {
      Transaction currentTx = Transaction.Current;
      if (currentTx != null)
      {
         currentTx.RollBack(new Exception("I give up!");
      }
   }