Beispiel #1
0
        public static void ExecInTrans(FactoryArgs args, ExecInTransDelegate execDelegate)
        {
            if (args.DbConnection != null && args.DbTrans != null)
            {
                execDelegate(args);
            }
            else
            {
                string dbName = args.DBName;
                using (DbConnection conn = Provider.CreateConnection(dbName))
                {
                    try
                    {
                        conn.Open();

                        IsolationLevel level;
                        //if( TS.DW.Setting.SettingDW.TransMode == 0 )
                        //{
                        //	level = IsolationLevel.ReadCommitted;
                        //}
                        //else
                        //{
                        //	level = IsolationLevel.ReadUncommitted;
                        //}
                        level = IsolationLevel.ReadUncommitted;
                        using (DbTransaction trans = conn.BeginTransaction(level))
                        {
                            using (DbCommand cmd = Provider.CreateCommand())
                            {
                                FactoryArgs argsTran = new FactoryArgs(args.DBName, args.LoginName, args.SessionID, args.IsNeedSession, conn, trans);
                                try
                                {
                                    execDelegate(argsTran);

                                    trans.Commit();
                                }
                                catch (Exception ex)
                                {
                                    try
                                    {
                                        trans.Rollback();
                                    }
                                    catch
                                    {
                                    }
                                    args.SelectResult = argsTran.SelectResult;
                                    throw ex;
                                }
                            }
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
Beispiel #2
0
        public static void ExecInTrans(DALExecuteArgs args, ExecInTransDelegate execDelegate)
        {
            if (args.DbConnection != null && args.DbTrans != null)
            {
                execDelegate(args.DbConnection, args.DbTrans);
            }
            else
            {
                string dbName = args.DBName;
                //using( DbConnection conn = Provider.CreateConnection( dbName ) )
                using (DbConnection conn = Provider.CreateConnection())
                {
                    try
                    {
                        conn.Open();

                        IsolationLevel level;
                        //if( TS.DW.Setting.SettingDW.TransMode == 0 )
                        if (iTransMode == 0)
                        {
                            level = IsolationLevel.ReadCommitted;
                        }
                        else
                        {
                            level = IsolationLevel.ReadUncommitted;
                        }
                        using (DbTransaction trans = conn.BeginTransaction(level))
                        {
                            using (DbCommand cmd = Provider.CreateCommand())
                            {
                                try
                                {
                                    execDelegate(conn, trans);

                                    trans.Commit();
                                }
                                catch (Exception ex)
                                {
                                    try
                                    {
                                        trans.Rollback();
                                    }
                                    catch
                                    {
                                    }
                                    throw ex;
                                }
                            }
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
Beispiel #3
0
        //public static void ExecInTrans( string dbName, ExecInTransDelegate execDelegate )
        public static void ExecInTrans(ExecInTransDelegate execDelegate)
        {
            using (DbConnection conn = Provider.CreateConnection())
            {
                try
                {
                    conn.Open();

                    IsolationLevel level;
                    //if( TS.DW.Setting.SettingDW.TransMode == 0 )
                    if (iTransMode == 0)
                    {
                        level = IsolationLevel.ReadCommitted;
                    }
                    else
                    {
                        level = IsolationLevel.ReadUncommitted;
                    }
                    using (DbTransaction trans = conn.BeginTransaction(level))
                    {
                        using (DbCommand cmd = Provider.CreateCommand())
                        {
                            try
                            {
                                execDelegate(conn, trans);

                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                try
                                {
                                    trans.Rollback();
                                }
                                catch
                                {
                                }
                                throw ex;
                            }
                        }
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
        }