Will an inner transaction scope roll back if the outer transaction scope doesn't complete?

Tebo picture Tebo · Dec 21, 2010 · Viewed 23.6k times · Source

I have two transaction scopes, one within another. I would love to know if the inner transaction scope will be rolled back after it has been committed and the outer one does not complete.

Answer

Greg Beech picture Greg Beech · Dec 21, 2010

It depends on the scope option you start the nested transaction scope with.

If you use the default option TransactionScopeOption.Required then the nested scope will enlist in the same transaction as the outer scope and as such when the outer scope rolls back the inner scope will also be rolled back even if it has called Complete.

If, however, you use TransactionScopeOption.RequiresNew then the nested scope will begin its own transaction and complete it separately from the outer scope, so it will not roll back even if the outer scope rolls back.

If you use TransactionScopeOption.Suppress then the nested scope will not take part in the outer transaction and will complete non-transactionally, thus does not form part of the work that would be rolled back if the outer transaction rolls back.