Пример #1
0
        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);
            }
        }
Пример #2
0
        private static SqlTransaction GetTransaction()
        {
            SqlTransaction ret  = null;
            McTransaction  tran = GetMcTransaction();

            if (tran != null)
            {
                ret = tran.SqlTransaction;
            }
            return(ret);
        }
Пример #3
0
        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;
        }
Пример #4
0
        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);
        }
Пример #5
0
        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());
            }
        }
Пример #6
0
 private static void SetTransaction(McTransaction tran)
 {
     Thread.SetData(Thread.GetNamedDataSlot(sSQLTransaction), tran);
 }
Пример #7
0
 private static void SetTransaction(McTransaction tran)
 {
     Thread.SetData(Thread.GetNamedDataSlot(sSQLTransaction), tran);
 }