Reputation: 1
I am trying to wrap two TransactionScopes within another TransactionScope, but when I run the program and an error is triggered in the 2nd transaction scope, the 1st transaction is not rolled back. Is it possible to rollback both, or am I better off doing something else. I had to separate them due to the TransactionScope locking rows in a table and not working right.
Using objTransaction As New Transactions.TransactionScope(Transactions.TransactionScopeOption.RequiresNew, New TimeSpan(0, 10, 0))
Using objTransaction As New Transactions.TransactionScope(Transactions.TransactionScopeOption.RequiresNew, New TimeSpan(0, 10, 0))
'Scope - 1
End Using
Using objTransaction As New Transactions.TransactionScope(Transactions.TransactionScopeOption.RequiresNew, New TimeSpan(0, 10, 0))
'Scope - 2
End Using
End Using
Upvotes: 0
Views: 933
Reputation: 1603
You're using the wrong transaction scope option. To have your inner TransactionScopes enlist in the parent scope you need to use the TransactionScopeOption.Required.
When you use TransactionScopeOption of Required it will enlist in the ambient transaction if one exists. When you use RequiredNew it won't enlist in a ambient transaction.
A great article explaining the differences is here
Upvotes: 2