public static void Rollback(bool newTran) { if (newTran) { McTransaction tran = GetMcTransaction(); if (tran != null) { SqlConnection cnn = null; if (tran.SqlTransaction.Connection != null) { cnn = tran.SqlTransaction.Connection; } try { tran.SqlTransaction.Rollback(); } catch {} if (cnn != null) { cnn.Close(); } } SetTransaction(null); } }
private static SqlTransaction GetTransaction() { SqlTransaction ret = null; McTransaction tran = GetMcTransaction(); if (tran != null) { ret = tran.SqlTransaction; } return(ret); }
public static bool BeginTransaction(bool newTran) { McTransaction tran = null; if(!newTran) tran = GetMcTransaction(); if(null == tran) { newTran = true; SqlConnection cnn = new SqlConnection(ConnectionString); cnn.Open(); tran = new McTransaction(cnn.BeginTransaction()); SetTransaction(tran); } return newTran; }
public static bool BeginTransaction(bool newTran) { McTransaction tran = null; if (!newTran) { tran = GetMcTransaction(); } if (null == tran) { newTran = true; SqlConnection cnn = new SqlConnection(ConnectionString); cnn.Open(); tran = new McTransaction(cnn.BeginTransaction()); SetTransaction(tran); } return(newTran); }
public static void Commit(bool newTran) { if (newTran) { McTransaction tran = GetMcTransaction(); if (tran != null) { SqlConnection cnn = null; if (tran.SqlTransaction.Connection != null) { cnn = tran.SqlTransaction.Connection; } try { tran.SqlTransaction.Commit(); } catch { try { tran.SqlTransaction.Rollback(); } catch {} throw; } finally { if (cnn != null) { cnn.Close(); } } } SetTransaction(null); tran.RaiseAfterCommit(tran.SqlTransaction.GetHashCode()); } }
private static void SetTransaction(McTransaction tran) { Thread.SetData(Thread.GetNamedDataSlot(sSQLTransaction), tran); }