public static void ExecuteNonQuery(this DbConnection conn, string sql, DbTransaction trans, int?timeout, ICancelableProcessCallback cancelable = null)
 {
     if (String.IsNullOrEmpty(sql))
     {
         return;
     }
     if (sql.StartsWith("@use"))
     {
         string[] items = sql.Split(' ');
         conn.ChangeDatabase(items[1].Trim());
     }
     else
     {
         using (DbCommand cmd = conn.CreateCommand())
         {
             cmd.CommandText = sql;
             if (timeout != null)
             {
                 cmd.CommandTimeout = timeout.Value;
             }
             if (trans != null)
             {
                 cmd.Transaction = trans;
             }
             cancelable?.AddCancelMethod(cmd, cmd.Cancel);
             cmd.ExecuteNonQueryEx();
             cancelable?.RemoveCancelMethod(cmd);
         }
     }
 }
Example #2
0
        public void Run()
        {
            try
            {
                _cancelable?.AddCancelMethod(this, () => _isCanceled = true);
                DoRun();

                if (IsFull)
                {
                    _dmp.Comment(" ******************************* SQL is truncated  ******************************* ");
                }
            }
            finally
            {
                _cancelable?.RemoveCancelMethod(this);
            }
        }