0

I have a problem that when root transaction scope dispose the nested completed transactions scopes not rolled back. I need to rollback all nested transaction scopes when dispose the root.

the root scope from the root wcf service

  using (var ts = new TransactionScope(TransactionScopeOption.Required,
            new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted, Timeout = new TimeSpan(0, 10, 0) },
            TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                   //logic ... and call the inner scope 


                    ts.Complete();
                    return result;
                }
                catch (Exception ex)
                {
                ts.Dispose();
                    throw ex;
                }

            }
        

the nested scope in another wcf service

 using (var ts = new TransactionScope(TransactionScopeOption.Required,
            new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted, Timeout = new TimeSpan(0, 10, 0) },
            TransactionScopeAsyncFlowOption.Enabled))
        {
            try
            {
             //logic

                ts.Complete();
                return result;
            }
            catch (Exception ex)
            {
                ts.Dispose();
                throw ex;
            }

        }

I need when the root scope disposed as a result of exception, roll back all inner transaction scopes

  • This is related to TransactionScopeOption. If the default option TransactionScopeOption.Required is used, the nested scope will be registered in the same transaction as the outer scope. Therefore, when the outer scope is rolled back, even if the inner scope has been called, the inner scope Complete will be rolled back.For more information about TransactionScope, please refer to this link:https://learn.microsoft.com/en-us/dotnet/api/system.transactions.transactionscope?view=netcore-3.1 – Ding Peng Aug 18 '20 at 07:25
  • I see that `ts.Complete();` is called on your root scope. If you want to rollback all nested transactions, you need to ensure `ts.Complete();` is not called on your root scope. Please refer to my other answer: https://stackoverflow.com/questions/28191333/transactionscope-error-in-ambient-transaction-does-not-rollback-the-transaction/28258935#28258935 – Khanh TO Aug 22 '20 at 02:35

0 Answers0