Logo




Subscribe:
RSS 2.0 | Atom 1.0
Categories:

Sign In


[Giagnocavo]Michael::Write()

 Saturday, February 26, 2005
Smart change to TransactionScope

In .NET 2, there's a new System.Transactions.TransactionScope class. It basically allows you to do implicit transactions just by creating a new TransactionScope. It's stored in TLS and things like SqlConnection check it and auto-enlist. A sample:

using (TransactionScope txScope = new TransactionScope)
{
insertSomethingIntoDB();
processCreditCard();
txScope.Complete();
}

This is different than Beta 1. In Beta 1, you had to set txScope.Consistent = true (it was implicitally false). I feel this is a great change, as using a method for completing a transaction is a lot more intuitive than using a property. I bet a lot of people would have run into errors with the old behaviour. Now, it's quite clear. When you're ready to commit, just call Complete. If you don't want to commit, then call Dispose (implicit with the using block).
Code
Saturday, February 26, 2005 4:24:30 PM UTC  #    Comments [1]  |  Trackback Tracked by:
"http://vmco6a9.com/lil-ass.html" (http://vmco6a9.com/lil-ass.html) [Pingback]


Saturday, February 26, 2005 7:24:36 PM UTC
This is the sucky part of betas - all the transactionscope examples I wrote now need to be changed!
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview