I've read about TransactionScope and this article, but I still don't understand 2 things:
SqlCommand.ExecuteNonQuery
is executed it doesn't really executed until scope.Complete()
is invoked? If it's true, so where all the operations that were executed within the scope are remain and wait for scope.Complete()
or scope.Rollback()
?TransactionScope
is instantiated how it prevents from SqlCommand.ExecuteNonQuery
to be executed and wait for scope.Complete()
or scope.Rollback()
? Does it creates some "place" and SqlCommand
somehow knows about it and puts the instructions in there?[1] When SqlCommand.ExecuteNonQuery is executed it doesn't really executed until scope.Complete() is invoked?
No this is not correct. Your command is executed on the line where you call ExecuteNonQuery
. It is, however, interesting to know where all the changes are stored. The changes do not go directly to the affected table(s) on the server side, rather the changes are stored in a temporary place (again on a server side), which leads to an answer on your second question
[2] When TransactionScope is instantiated how it prevents from SqlCommand.ExecuteNonQuery to be executed and wait for scope.Complete() or scope.Rollback()?
It does not prevent as such, the action is executed, but because the result of the action is stored in a temporary location you must either merge these changes with the main table(s) - scope.Commit()
or discard these changes - scope.Rollback()
(or whatever is used to discard the changes in the specific database data provider)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With