![]() |
Platforms, Frameworks & Libraries »
.NET Framework »
General
Intermediate
Implementing TransactionScope Using .Net 2.0By Chandrashekhar KulkarniAn overview of TransactionScope feature in .net 2.0 |
C# 2.0, Windows, .NET 2.0VS2005, Dev
|
||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
In earlier development tools, the database transaction management was an isolated topic that required separate thought process. Considering the example of heterogeneous production and development environment where the application is interacting with multiple databases, transaction management was tedious task.
Several legacy systems are on the verge of migration; however, these legacy systems have a serious constraint from back-end point of view. Due to the business risks involved database migration is usually considered as a separate project. Also, real time applications cannot take the risk of downtime in the production environment due to business constrains.
Under such circumstances, application enhancement or new supplementary automations are required to communicate with legacy database and other latest databases as well. This interaction, several times is observed to be a transaction based interaction.
New release of Microsoft .net 2.0 resolves this issue with a new feature called as the "Transaction Scope". In this article, we will discuss in brief the overview of this feature.
This article requires prior knowledge of database Transaction implementation.
Then lets start here....
TransactionOptions TransOpt = New TransactionOptions(); TransOpt.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; TransOpt.Timeout = New TimeSpan(0, 2, 0);
using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TransOptions)) using(TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TransOptions)) using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress, TransOptions))
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { string strCmd = "SQL to Execute"; conn = new SqlClient.SqlConnection("Connection to DB1"); conn.Open() objCmd = new SqlClient.SqlCommand(strCmd, conn); objCmd.ExecuteNonQuery(); string strCmd2 = "SQL to Execute"; conn2 = new SqlClient.SqlConnection("Connection to DB2"); conn2.Open() objCmd2 = new SqlClient.SqlCommand(strCmd2, conn2); objCmd2.ExecuteNonQuery(); }


http://msdn.microsoft.com/msdnmag/issues/06/11/DataPoints/default.aspx
http://msdn2.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
http://msdn2.microsoft.com/en-us/library/system.transactions.transactionscopeoption.aspx
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 29 May 2007 Editor: |
Copyright 2007 by Chandrashekhar Kulkarni Everything else Copyright © CodeProject, 1999-2009 Web10 | Advertise on the Code Project |