public bool RunQuery(string query, CommandType commandType, SqlParameter[] arPara, bool WaiRunOK = false, int TryRun = 0) { int iRun = 0; while (true) { try { this.command.CommandType = commandType; this.command.CommandText = query; this.command.Parameters.Clear(); if (arPara != null) { this.command.Parameters.AddRange(arPara); } if (this.command.Connection.State == ConnectionState.Closed) { this.command.Connection.Open(); } this.command.ExecuteNonQuery(); return(true); } catch (SqlException ex) { if (ex.Number == -2) { log.Error(ex.Message); iRun++; if (WaiRunOK == false && iRun >= TryRun) { return(false); } } else { log.Info(ex.Message + ex.StackTrace + query + CommonConvert.ArParaToString(arPara)); return(false); } } catch (Exception ex) { if (!WaiRunOK) { log.ErrorFormat("Exception sql run" + ex.Message + ex.StackTrace + command.CommandText); return(false); } else { Thread.Sleep(10000); } } } }