public void Multiple()
        {
            int Tcount = 0;

            Console.WriteLine(DateTime.Now.ToString());
            while (Tcount++ < 2000)
            {
                try
                {
                    Single();
                    txtBox.Text = "" + Tcount;
                }
                catch (SocketException e)
                {
                    throw e;
                }
                catch (Exception)
                {
                    if (tr != null)
                    {
                        tr.Rollback();
                    }
                    Form1.wconflicts++;
                }
            }
            Console.WriteLine(DateTime.Now.ToString());
        }
Example #2
0
        /// <summary>
        /// 执行多条SQL语句,实现数据库事务。
        /// </summary>
        /// <param name="SQLStringList">ArrayList</param>
        public static void ExecuteSqlTran(ArrayList sqlList, string ConString)
        {
            bool mustCloseConnection = false;

            using (DB2Connection conn = new DB2Connection(ConString))
            {
                conn.Open();
                using (DB2Transaction trans = conn.BeginTransaction())
                {
                    DB2Command cmd = new DB2Command();
                    try
                    {
                        for (int i = 0; i < sqlList.Count; i++)
                        {
                            string cmdText = sqlList[i].ToString();
                            PrepareCommand(cmd, conn, trans, CommandType.Text, cmdText, null, out mustCloseConnection);
                            int val = cmd.ExecuteNonQuery();
                        }
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                    finally
                    {
                        conn.Close();
                        cmd.Dispose();
                    }
                }
            }
        }
Example #3
0
        private bool ExecuteNonQuery(DBRequest request)
        {
            //Controllo
            if (!registered.Contains(request.Controller))
            {
                throw new Exception("Il Controller non è registrato all'inizio dell'esecuzione");
            }

            //Inizio
            DB2Transaction transaction = databaseConnection.GetTransaction();
            DB2Command     command     = databaseConnection.GetCommand();

            command.CommandText = request.Command;
            command.Transaction = transaction;

            //Esecuzione
            try {
                command.ExecuteNonQuery();
            }
            catch (Exception e) {
                throw new Exception("Errore: " + e.Message);
            }

            //Controllo
            if (!registered.Contains(request.Controller))
            {
                transaction.Rollback();
                throw new Exception("Il Controller non è registrato alla fine dell'esecuzione");
            }

            //Fine
            transaction.Commit();
            return(true);
        }
        /// <summary>
        /// Inserir Veículo no Estacionamento
        /// </summary>
        public void EntrarVeiculo([FromBody] EstacionamentoModel obj)
        {
            if (!conexao.IsOpen)
            {
                conexao.Open();
            }

            DB2Transaction trans = conexao.BeginTransaction();

            try
            {
                new EstacionamentoDao(conexao, trans).EntrarVeiculo(obj);
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw new Exception(ex.Message);
            }
            finally
            {
                if (conexao.IsOpen)
                {
                    conexao.Close();
                }
            }
        }
Example #5
0
 public void RollbackTransaction()
 {
     try
     {
         Trans.Rollback();
     }
     catch (Exception)
     {
         throw;
     }
 }
        public bool RollbackTransaction()
        {
            try
            {
                trans.Rollback();

                return(true);
            }
            catch (Exception ex)
            {
                LastError = ex.Message;
                Logger.WriteLogExcept(LogTitle, ex);

                return(false);
            }
            finally
            {
                trans = null;
            }
        }
Example #7
0
        public bool Transaction(ArrayList sql)
        {
            bool   commit     = true;
            String exceptions = "";

            DB2Command     command = new DB2Command();
            DB2Transaction trans   = connection.BeginTransaction();

            command.Connection  = connection;
            command.Transaction = trans;

            for (int i = 0; i < sql.Count; i++)
            {
                command.CommandText = sql[i].ToString();

                try
                {
                    command.ExecuteNonQuery();
                }
                catch
                {
                    exceptions += String.Format("error ejecutando: {0}\n", sql[i]);
                    commit      = false;
                }
            }

            if (commit)
            {
                trans.Commit();
            }

            else
            {
                trans.Rollback();
            }

            Exceptions = exceptions;
            return(commit);
        }
        /// <summary>
        /// Retirar Veículo do Estacionamento
        /// </summary>
        public double SairVeiculo(int codigo)
        {
            try
            {
                if (!conexao.IsOpen)
                {
                    conexao.Open();
                }
                if (transacao == null)
                {
                    transacao = conexao.BeginTransaction();
                }

                DateTime dataEntrada = new EstacionamentoDao(conexao, transacao).BuscarDataEntradaVeiculo(codigo);
                DateTime dataSaida   = DateTime.Now;

                TimeSpan duracao = new TimeSpan(dataSaida.Ticks - dataEntrada.Ticks);

                new EstacionamentoDao(conexao, transacao).SairVeiculo(codigo);

                transacao.Commit();

                return(0);
            }
            catch (Exception ex)
            {
                transacao.Rollback();
                throw new Exception(ex.Message);
            }
            finally
            {
                if (conexao.IsOpen)
                {
                    conexao.Close();
                }
            }
        }
Example #9
0
        private DBReaderController ExecuteQuery(DBRequest request)
        {
            //Controllo
            if (!registered.Contains(request.Controller))
            {
                throw new Exception("Il Controller non è registrato all'inizio dell'esecuzione");
            }

            //Inizio
            DBReaderController result;
            DB2DataReader      reader;
            DB2Transaction     transaction = databaseConnection.GetTransaction();
            DB2Command         command     = databaseConnection.GetCommand();

            command.CommandText = request.Command;
            command.Transaction = transaction;

            //Esecuzione
            try {
                reader = command.ExecuteReader();
            }
            catch (Exception e) {
                throw new Exception("Errore in lettura: " + e.Message);
            }

            //Controllo
            if (!registered.Contains(request.Controller))
            {
                transaction.Rollback();
                throw new Exception("Il Controller non è registrato alla fine dell'esecuzione");
            }

            //Fine
            transaction.Commit();
            return(result = new DBReaderController(reader));
        }
Example #10
0
 /// <summary>
 /// 导入
 /// </summary>
 /// <param name="recc"></param>
 /// <param name="connectStr"></param>
 /// <param name="sql"></param>
 /// <param name="allDB2Para"></param>
 /// <returns></returns>
 public static bool Import(int recc, string connectStr, string sql, IList <DB2Parameter> allDB2Para)
 {
     //设置一个数据库的连接串
     using (DB2Connection conn = new DB2Connection(connectStr))
     {
         conn.Open();
         DB2Transaction transaction = conn.BeginTransaction();
         try
         {
             DB2Command command = new DB2Command();
             command.Connection  = conn;
             command.CommandType = CommandType.Text;
             command.Transaction = transaction;
             //到此为止,还都是我们熟悉的代码,下面就要开始喽
             //这个参数需要指定每次批插入的记录数
             command.ArrayBindCount = recc;
             //在这个命令行中,用到了参数,参数我们很熟悉,但是这个参数在传值的时候
             //用到的是数组,而不是单个的值,这就是它独特的地方
             command.CommandText = sql;
             //下面定义几个数组,分别表示三个字段,数组的长度由参数直接给出
             foreach (var t in allDB2Para)
             {
                 command.Parameters.Add(t);
             }
             //这个调用将把参数数组传进SQL,同时写入数据库
             command.ExecuteNonQuery();
             transaction.Commit();//提交事务
         }
         catch (Exception e)
         {
             transaction.Rollback();//事务回滚
             throw e;
         }
     }
     return(true);
 }
Example #11
0
        public bool Transaction(ArrayList sql)
        {
            int  numQueries = 0, i = 0;
            bool status = false;

            DB2Command    command = new DB2Command();
            DB2Connection con     = OpenConnection();

            command.Connection = con;

            DB2Transaction trans = con.BeginTransaction();

            command.Transaction = trans;

            for (i = 0; i < sql.Count; i++)
            {
                AdministradorCarpetasRegistro.GrabarLogs(TipoRegistro.Actividad, (string)sql[i], null, string.Empty);
                command.CommandText = sql[i].ToString();
                try
                {
                    command.ExecuteNonQuery();
                    exceptions += "ejecutando: " + sql[i] + cambioLinea;
                    numQueries++;

                    HistorialSeguimientoTabla(TABLA_SEGUIR, sql[i].ToString());  //Almacenamiento historial de seguimiento a tabla.
                }
                catch (Exception ex)
                {
                    exceptions += String.Format("error ejecutando: {0} \n {1} \n", sql[i], ex.Message);
                    status      = false;
                }
            }

            if (numQueries == sql.Count)
            {
                try
                {
                    trans.Commit();
                    exceptions += "ejecutando Commit -- " + cambioLinea;
                    status      = true;
                }
                catch (Exception e)
                {
                    exceptions += "Error ejecutando Commit: " + e.ToString();
                    AdministradorCarpetasRegistro.GrabarLogs(TipoRegistro.Error, string.Empty, e, exceptions);
                    status = false;
                }
            }
            else
            {
                try
                {
                    trans.Rollback();
                }
                catch (Exception e)
                {
                    exceptions += "Error ejecutando RollBack: " + e.ToString();
                    AdministradorCarpetasRegistro.GrabarLogs(TipoRegistro.Error, string.Empty, e, exceptions);
                }
                numQueries = 0;
            }

            CloseConnection(con);

            return(status);
        }
Example #12
0
 public void rollback()
 {
     trans.Rollback();
 }
Example #13
0
 /// <summary>
 /// 事务回滚
 /// </summary>
 public override void RollbackTrans()
 {
     _trans.Rollback();
     _isInTransaction = false;
 }