Blog Stats
  • Posts - 52
  • Articles - 0
  • Comments - 6
  • Trackbacks - 12

 

Simplicity with System.Transactions

In .Net 1.0 the support for transactions is located on System.EnterpriseServices namespace. This model has some disadvantages because you have to inherit from the ServiceComponent class and then you have to registers the components in the COM+ Catalog (with regsvcs). Apart from that this model offers local transactions in a specific database.

With the avenue of COM+ 1.5 a new feature called Service without Components appeared, with this feature we don’t have to inherit from the ServiceComponent class and even better we don’t need any registration in the COM+ Catalog. Also the programming model was easier from the developer point of view and we were all happy.

In .Net 2.0 there is a new namespace named System.Transactions to handle all the related transactional tasks. This offer the developer and extremely easy programming model plus other features like transaction control spanned over multiple databases.

Code Example:

using System;
using System.Transactions;

namespace TransactionExample
{
   public class Program
   {
      static void Main(string[] args)
      {
         using (TransactionScope ts = new TransactionScope())
         {

            // Create connection to database 1
            // the data provider will detect the transaction and automatically enlist into the DTC
 
            // Create connection to database 2
            // the data provider will detect the transaction and automatically enlist into the DTC

 

            // the following code will be executed only if no exception occurred in the above code;
            ts.Complete();

         }

      }
   }
}

The power of this, is that with the same programming model we can have local transactions or distributed transactions spanned over multiple databases.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: Simplicity with System.Transactions

Gravatar There is a mistake in the first paragraph, the transactions in COM+ are always distributed, still in COM+ 1.0, the problem there is that you can't define the isolation level. :-) 8/18/2005 8:35 PM | Heero Yuy

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Pablo Galiano