Understanding Transaction in ADO.NET
page 5 of 8
Average Rating: 
Views (Total / Last 10 Days): 48521/ 109

Distributed Transaction

The .NET Framework 2.0 includes the System.Transactions namespace, which provides support for distributed transactions and defines the TransactionScope class, which enables us to create and manage distributed transactions.  We can implement transactions for multiple database connections using TransactionScope.

Listing 6

using(TransactionScope tranScope = new TransactionScope())
  string cString =
  string cString1 =
  using(SqlConnection con = new SqlConnection(cString))
    SqlCommand cmd = codesDatabaseConnection.CreateCommand();
    cmd.CommandText =
      "Insert Into Emp (Emp_Code, Emp_Name) values (1,'Employee1')";
  using(SqlConnection con1 = new SqlConnection(cString1))
    SqlCommand cmd1 = con1.CreateCommand();
    cmd1.CommandText = "Insert into Emp_Detailas(Emp_ID,Sal) values (1, 8000)";

If all the update operations succeed in a transaction scope, we should call the complete method on the TransactionScope object to indicate that the transaction completed successfully and, thus, the transaction manager commits the transaction. 

View Entire Article

User Comments

No comments posted yet.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2022 ASPAlliance.com  |  Page Processed at 2022-05-16 2:28:01 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search