Hello Mukesh,
It's because you methods use SqlConnection that can be enlisted in Transaction
Manager
I recomend to read this article
http://www.microsoft.com/downloads/d...displaylang=en
in the beginning Juwal open this subject
M> To test TransactionScop e behaviour I created four table t1, t2, t3,t4
M> wil only one column sl. Four method m1, m2, m3 and m4 insert one row
M> to these tables respectively. These methods are independent
M> otherwise.
M> There is a method Call_Methods() which will call m1, m2, m3 and m4
M> within transaction scope. m1 get executed. I checked this table
M> from
M> Query analyzer. The row was locked. After calling m3 exception is
M> thrown and as exception handler TransactionScop e is disposed. To my
M> surprise no changes was done to any tables. It means
M> TransactionScop e automatically started transaction in each method.
M> How it happened? What if m2 uses m1 updated values?
M>
M> private void Call_Methods()
M> {
M> using (TransactionSco pe scope = new TransactionScop e())
M> {
M> Exception ee = new Exception("Muke sh created
M> exception");
M> try
M> {
M> m1();
M> m2();
M> m3();
M> throw ee;
M> m4();
M> scope.Complete( );
M> }
M> catch (Exception ex)
M> {
M> MessageBox.Show ("Exception Occured" +
M> ex.Message);
M> scope.Dispose() ;
M> }
M> }
M> }
M> private void m1()
M> {
M> string conStr = "Persist Security Info=False;User
M> ID=sa;Password= 931;Initial Catalog= mukesh; Data
M> Source=10.26.5. 125\\LOCAL_MUKE SH";
M> SqlConnection cn;
M> cn = new SqlConnection(c onStr);
M> cn.Open();
M> SqlCommand cmd = new SqlCommand("Ins ert into t1
M> values(1)",
M> cn);
M> cmd.ExecuteNonQ uery();
M> cn.Close();
M> }
M> private void m2()
M> {
M> string conStr = "Persist Security Info=False;User
M> ID=sa;Password= 931;Initial Catalog= mukesh; Data
M> Source=10.26.5. 125\\LOCAL_MUKE SH";
M> SqlConnection cn;
M> cn = new SqlConnection(c onStr);
M> cn.Open();
M> SqlCommand cmd = new SqlCommand("Ins ert into t2
M> values(2)",
M> cn);
M> cmd.ExecuteNonQ uery();
M> cn.Close();
M> }
M> private void m3()
M> {
M> string conStr = "Persist Security Info=False;User
M> ID=sa;Password= 931;Initial Catalog= mukesh; Data
M> Source=10.26.5. 125\\LOCAL_MUKE SH";
M> SqlConnection cn;
M> cn = new SqlConnection(c onStr);
M> cn.Open();
M> SqlCommand cmd = new SqlCommand("Ins ert into t3
M> values(3)",
M> cn);
M> cmd.ExecuteNonQ uery();
M> cn.Close();
M> }
M> private void m4()
M> {
M> string conStr = "Persist Security Info=False;User
M> ID=sa;Password= 931;Initial Catalog= mukesh; Data
M> Source=10.26.5. 125\\LOCAL_MUKE SH";
M> SqlConnection cn;
M> cn = new SqlConnection(c onStr);
M> cn.Open();
M> SqlCommand cmd = new SqlCommand("Ins ert into t4
M> values(4)",
M> cn);
M> cmd.ExecuteNonQ uery();
M> cn.Close();
M> }
M> Thanks
M> Mukesh
---
WBR,
Michael Nemtsev :: blog:
http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche