posted on Wednesday, November 09, 2005 8:22 AM by scotts

TVUG with John Papa and System.Transaction thoughts

John Papa presented at the TVUG last night; his topics were ado.net 2.0 and system.transaction. Johnny did a great job and it was good to see him again.

I’ve been excited about system.transaction since first trying it out in beta 1,and blogged a little about system.transaction and talked about a Data Points article that Johnny wrote covering the topic back at the beginning of the year.

There is a lot to like about system.transaction. One of my favorites is the good granular control over the scope of your transaction. Yes, it is really slick how a lightweight transaction can get promoted to a full distributed transaction all dynamically at runtime, simply based on if it is needed or not. Everyone seems to talk about this and it is indeed very cool. However, one of my personal favorites about system.transaction, is that you no longer have to make the transaction decision at the class level!

In 1.x, in order to play with DTC, you inherited from System.EnterpriseServices. But here is the killer: you had to decide if a given class was going to require, require new, support, or not support transactions; at the class level! All you could do in a method was vote on it, either implicitly with AutoComplete(true) or explicitly using SetCommit/SetAbort.

So, if you had a single class that was going to do some db work, you had to either allow your select stuff to take part in transactions (silly), or create 2 types of the class; one to do the non-transactional work, and another to do the transaction work. What I had been dying for was the ability to make that decision at the method level; method A requires a transaction, method B does not. Then you could create the one class to do this DB work and not worry about the "select only" methods creating a transaction. Well now we got it!

With System.Transaction, the scope of the transaction is completely at your control and it is no longer a class level decision. So, yes the auto promotion stuff is really cool and it is going to get the ooh’s and the ah’s, and rightfully so. But, in my mind it’s icing on the cake to the granular control of the transaction scope.

Comments