views:

36

answers:

1

I am tasked with proving or disproving the transaction support in .net. We all know that the TransactionScope can handle committing/rolling back simple things like inserting 3 records in 3 different tables and then deleting 5 records in 5 other tables.

My team is not so sure that TransactionScope can handle the transaction properly if these inserts/deletes have triggers. Or if we execute a SP that has it's own nested transactions.

Does the .net transaction support handle these more complicated situations? Do you have to specify any not-so-obvious options to make it all work?

I've heard that some of our SPs could cause us problems, since a few commit sub transactions on their own. Does anyone know if this particular scenario is handle by TransactionScope?

+2  A: 

We are using TransactionScope for some very complex and lengthy database operations involving thousands of rows across a dozen or more tables. It handles it just fine. However, IMO, you DO NOT want to be starting and committing transactions in stored procedures and/or triggers.You should let your calling (C#) code handle that. You lose a great deal of flexibility by handling transactions at the lower stored proc level.

Also, be careful, when using TransactionScope, to limit yourself to a single connection object. If you don't, the transaction will escalate to a MTC transaction, which requires the MTC service to be running on the client and server.

Randy Minder
I assume you're using quite a few SPs and triggers? My team (i'm not so much) are particularly worried about SPs that have their own nested transactions. Also we have a few triggers/indexes that must maintain integrity and if we insert on table1-column1 a trigger inserts into table2-column2 and if these tables ever got out of sync it would be VERY bad.Any elaboration you can provide would much appreciated. Thanks for your initial response as well.
Sublimemm
Thanks for the TIP on MTC, we've already ran into this and have it running on both client server. If only I could have read your comment a few months ago I wouldn't have spent 3 days figuring out why my SIMPLE statement wasn't working :0
Sublimemm
@Sublimemm - You can have as many triggers firing as you want, adding rows to as many tables as you want. The use of TransactionScope will handle the commit and rollback of this just fine. But, you are asking for trouble committing or rolling back transactions in stored procedures. You should not be doing this (IMO).
Randy Minder