views:

38

answers:

2

Hi,

Can you guys tell me the difference between these two objects? Thanks!

+1  A: 

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
Thanks Andrew. So, If I use a TransactionScope, then I would not have to use a MySqlTransaction too. Correct?
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
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.
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?
A: 

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

Prakash Kalakoti