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

后端 未结 2 655
误落风尘
误落风尘 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
    

提交回复
热议问题