Can you guys tell me the difference between these two objects? Thanks!
Asked
Active
Viewed 473 times
0
-
In addition to the answer given by Andrew Kennan. You can also check http://stackoverflow.com/questions/542525/transactionscope-vs-transaction-in-linq2sql/542704#542704 – PSK Jul 24 '10 at 07:07
1 Answers
1
A MySqlTransaction is a MySQL specific implementation of System.Data.IDbTransaction, that is it represents a transaction in a MySQL database.
TransactionScope is used to make blocks of code, not just database calls, transactional.
The TransactionScope will enlist the MySqlTransaction as part of a larger transactional code block so you can perform some database writes and other things as part of the transactionscope and either they will all be committed or they will all be rolled back.

Andrew Kennan
- 13,947
- 3
- 24
- 33
-
Thanks Andrew. So, If I use a TransactionScope, then I would not have to use a MySqlTransaction too. Correct? – user355562 Jul 24 '10 at 06:50
-
If all you are doing is writing to MySQL you probably don't need the TransactionScope. If you do need other transactional operations you should use both as the TransactionScope will enlist the MySqlTransaction. – Andrew Kennan Jul 24 '10 at 06:54
-
As I understand it, once a TransactionScope is created, all the connections opened later on will come in it's scope. Then, won't the use of MySQLTransaction be superficial? i.e. If my code is anyway going to commit or rollback because of the use of TransactionScope, then why should it be handled at MySQL level? Or am I not correct in my understanding? Thanks. – user355562 Jul 24 '10 at 07:02
-
Just to add to the above, the functions that are invoked might do an insert/update/delete at various places during the execution. So, won't putting all these function calls under a single TransactionScope be sufficient? Or should all the functions have their own transactions (MySqlTransaction) with the TransactionScope being the root transaction? – user355562 Jul 24 '10 at 07:05