.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML

Ado.netAsp.Net 2.0SQLC-SharpXMLFrameworkIISXMLWebServiceArchitecture
UMLProject ManagementSDLCMethodologiesDesign PatterenOOPWCF.Net RemotingWWF
MVPMVCSilver LightN-HibernateAjaxJ-QuerySEO-MarketingSite MapPhp

.Distributed Transaction in.net



Add a reference to the System.Transactions assembly.
Distributed transaction .net 2.0
using System;
1:using System.Data;
2:using System.Data.SqlClient;
3:using System.Transactions;
4:
5:namespace Arindam.DistributedTransaction
6:{
7: public class Distributed_Transaction_using_system_transaction
8: {
9: void DistributeData()
10: {
11:
12: TransactionOptions options = new TransactionOptions();
13: options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
14: options.Timeout = new TimeSpan(0, 2, 0);
15:
16: using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
17: {
18: using (SqlConnection connA = new SqlConnection(connStringA))
19: {
20: using (SqlCommand cmdA = new SqlCommand(sqlStmtA, connA))
21: {
22: int rowsAffectedA = cmdA.ExecuteNonQuery();
23: if (rowsAffectedA > 0)
24: {
25: using (SqlConnection connB = new SqlConnection(connStringB))
26: {
27: using (SqlCommand cmdB = new SqlCommand(sqlStmtB, connB))
28: {
29: int rowsAffectedB = cmdB.ExecuteNonQuery();
30: if (rowsAffectedB > 0)
31: {
32: transactionScope.Complete();
33: }
34:
35: } // Dispose the second command object.
36:
37: } // Dispose (close) the second connection.
38:
39: }
40:
41: } // Dispose the first command object.
42:
43: } // Dispose (close) the first connection.
44:
45: } // Dispose TransactionScope object, to commit or rollback transaction
46:
47: }
48: }
49:}
50:
Leave your comment.
Name
Email
Comments
Tell Us4687+5 =

Reduce your Dialy IT Cost, Consult with us
Stay healthy in recession

Advertisement
Sponsored by

Privacy Policy ©2009 ETG Consultancy, All Rights Reserved Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML