2010-06-07 74 views
1

當調用Commit(用於IEnlistmentNotification的實現)時,我是否可以引發異常來指示我希望事務回滾?IEnlistmentNotification接口的兩階段提交

+2

後'Commit'被稱爲是爲時已晚回滾。 – 2010-06-07 17:55:55

+0

實際上,沒有 - 直到Enlistment.Done()在實現實例中調用,仍然有機會回滾! – 2010-06-07 22:20:44

+0

我的回答不是你要找的東西嗎? – 2010-08-05 20:49:53

回答

0

而應該叫Transaction.Rollback(Exception ex)

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

根據我的測試代碼,當調用Commit()方法時,似乎Transaction.Current始終爲空。有任何想法嗎? – matori82 2014-01-13 15:21:12