TransactionScope TransactionAborted Exception - transaction not rolled back. Should it be?

后端 未结 2 638
误落风尘
误落风尘 2020-12-31 01:48

(SQL SERVER 2008) If a Transaction Timeout error occurs within a TransactionScope (.Complete()) would you expect the transaction to be rolled back?

Update:
The

相关标签:
2条回答
  • 2020-12-31 02:17

    I'm thinking that the TransactionAbortedException is actually a timeout. If so you should find that the InnerException of the TransactionAbortedException is a timeout.

    You should be able to get rid of it by making sure that the timeout of the transactionscope is longer than the command timeout.

    Try changing the transaction scope to something like this:

    new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(60))
    

    And also set an explicit timeout on your context. Should be something like:

    myContext.CommandTimeout = 30; //This is seconds
    
    0 讨论(0)
  • 2020-12-31 02:17

    I resolve this problem modifying the "physical file" machine.config.

    1. You have to localize the file:

    • 32 Bits: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machie.config
    • 64 Bits: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

    2. You have to add the following code:

    <system.transactions>
         <defaultSettings timeout="00:59:00" />
    </system.transactions>
    
    0 讨论(0)
提交回复
热议问题