I am just starting to work with using TransactionScope, I find that there are always unexpected things I run into that take forever to debug.
I figure that having a consolidated list of these would be great for those "weird error" circumstances, plus to expand our knowledge of oddness in the platform.
Some context on how I am going to be using transaction scopes:
Reinstalling MSDTC may reset MSDTC Security Configuration options back to default values. Verify that the MSDTC Security Configuration options are set to the appropriate values after reinstalling MSDTC. Reinstalling MSDTC may change the Startup Type value for the Distributed Transaction Coordinator service.
The TransactionScope class provides a simple way to mark a block of code as participating in a transaction, without requiring you to interact with the transaction itself. A transaction scope can select and manage the ambient transaction automatically.
Microsoft Distributed Transaction Coordinator (popularly known as MSDTC) is a coordinator to handle the distributed transactions. A distribution transaction involves two or more databases in a single transaction.
Is MSDTC required? MSDTC is not required for Sql Server installation or operation. If you are only going to use Database Engine, then it is not required or used. If your Sql uses any of the above mentioned query techniques (Linked Server, OPENQUERY, etc), or SSIS or Workstation Components then MSDTC is required.
2 things off the top of my head:
You want transactions to be lightweight as much as possible, dtc introduces a lot of overhead. You also want transactions to be as short as possible, so introduce them only on the application servers and not on the web server. Make the hop over the network between the application servers and the database as small as possible and as fast as possible, send network traffic between web and app servers over a different connection than between app servers and db, and make the last one a screaming fast, ridiculously short connection.
If you have multiple application servers, you could consider having a single instance of msdtc running on a server (e.g. on the database or on one of the app servers) and use this remotely from all application servers instead of each one running their own, but I don't know what additional benefits this has.
Hopefully this will help someone one day:
If you have a TransactionScope with multiple SQL operations inside, the DTC will not be involved provided
I.e. open, do someting, close. open, do something, close.
Now for the gotcha: if you ever do this in your process (on another thread)
SqlConnection.ClearAllPools()
and that happens to come between your two operations - the DTC will be involved immediately. If you don't have the DTC running, it will throw an Exception.
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