Jim jhonson has some good stuff on dependent transaction and transaction scope class for the new system.transaction class an drelated features in .Net2.0.
however how can not post the post of ballidos and sahil
http://blogs.msdn.com/angelsb/archive/2004/07/07/175586.aspx http://blogs.msdn.com/angelsb/archive/category/6274.aspx
http://codebetter.com/blogs/sahil.malik/archive/2004/12/06/35314.aspx and
http://www.windowsitpro.com/SQLServer/Articles/ArticleID/46104/pg/2/2.html
So here go how you can manipulate the same :with a small example:-
For intro watch msdntv and
add a ref to transaction.dll
using System;
using System.Transactions;
using System.Data;
using System.Data.SqlClient;
// Start a transaction.
//if not using the sqlserver explicitly enlist is reqd and if we ve multiple resource manager then
//it ll be taken care by msdtc what we ll do is insert a single record and then inside the trasaction scope we ll insert another
//with a diff connection the sql provider ll enlist in same transaction by default
//the final commit staement is somewaht awakward as it shows Consistent = true not .commit or rollback????(may be u can answer them)
namespace transactiontest
{
class testtran
{
static void Main(string[] args)
{
using (TransactionScope Tscope = new TransactionScope())
{
//sql provider automatically enlist in the trasaction
using (SqlConnection con = new SqlConnection("connstr here"))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "INSERT INTO emp VALUES (‘shree’, 30,4000)";
con.Open();
cmd.ExecuteNonQuery();
}
}
using (SqlConnection con = new SqlConnection("connstr here"))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "INSERT INTO dept VALUES (‘software’, 20,’acc’)";
conn.Open();
cmd.ExecuteNonQuery();
}
}
Console.WriteLine("want to Commit?");
string ans = Console.ReadLine();
if (ans == "yes")
{
Tscope .Consistent = true;
}
}
}
}
}