public SqlHelperTransaction2() { DisplayTransactioninfo.Display(committran); conn1.Open(); conn1.EnlistTransaction(committran); conn2.Open(); conn2.EnlistTransaction(committran); DisplayTransactioninfo.Display(committran); }
public void Add6() { try { DisplayTransactioninfo.Display(commit); SqlCommand command = new SqlCommand("insert into test2 values(111)", conn1); command.ExecuteNonQuery(); Thread thread = new Thread(SqlHelperTransaction1.CommitThread); thread.Start(commit.DependentClone(DependentCloneOption.BlockCommitUntilComplete)); commit.Commit(); } catch (Exception err) { commit.Rollback(); } }
public static void CommitThread(object co) { DependentTransaction commit = co as DependentTransaction; SqlConnection conn2 = new SqlConnection("data source=.;Initial Catalog=DataMedicine;Integrated Security=SSPI"); conn2.Open(); conn2.EnlistTransaction(commit as DependentTransaction); DisplayTransactioninfo.Display(commit); SqlCommand command = new SqlCommand("insert into test values(111)", conn2); try { command.ExecuteNonQuery(); commit.Complete(); } catch (Exception err) { Console.WriteLine(err); commit.Rollback(); } }