public int ExecuteNonQuery(SpCall spCall) { SetConnection(); SqlCommand command = CreateCommand(spCall); if (logger.IsDebugEnabled) { LogCommandInfo("ExecuteNonQuery", spCall); } if (command == null) { throw new ArgumentNullException("command"); } try { DateTime start = DateTime.Now; try { return(command.ExecuteNonQuery()); } catch (SqlException e) { logger.Fatal(e, string.Format("Exception while executing spCall{0}{1}", Environment.NewLine, spCall.ToString())); throw; } finally { TimeSpan span = DateTime.Now - start; if (!InTransaction) { CloseDbConnection(); } command.Parameters.Clear(); /* * if (span.TotalMilliseconds > thresholdTimeValue) * { * LogLongRunningCall(span, sp); * }*/ } } finally { command.Dispose(); } }
public T ExecuteScalar <T>(SpCall spCall) { if (logger.IsDebugEnabled) { LogCommandInfo("ExecuteScalar", spCall); } SetConnection(); using (SqlCommand cmd = CreateCommand(spCall)) { DateTime start = DateTime.Now; try { object result = cmd.ExecuteScalar(); return((T)Convert.ChangeType(result, typeof(T))); } catch (SqlException e) { logger.Fatal(e, string.Format("Exception while executing spCall{0}{1}", Environment.NewLine, spCall.ToString())); throw; } finally { TimeSpan span = DateTime.Now - start; if (!InTransaction) { CloseDbConnection(); } cmd.Parameters.Clear(); } } }
public DataSet ExecuteDataSet(SpCall spCall) { if (logger.IsDebugEnabled) { LogCommandInfo("ExecuteDataSet", spCall); } SetConnection(); using (SqlCommand cmd = CreateCommand(spCall)) { using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DateTime start = DateTime.Now; try { DataSet ds = new DataSet(); da.Fill(ds); return(ds); } catch (SqlException e) { logger.Fatal(e, string.Format("Exception while executing spCall{0}{1}", Environment.NewLine, spCall.ToString())); throw; } finally { TimeSpan span = DateTime.Now - start; if (!InTransaction) { CloseDbConnection(); } cmd.Parameters.Clear(); } } } }
public SqlReader ExecuteReader(SpCall spCall) { if (logger.IsDebugEnabled) { LogCommandInfo("Select", spCall); } SetConnection(); SqlCommand cmd = null; try { cmd = CreateCommand(spCall); SqlReader reader = new SqlReader(cmd, spCall); readers.Add(reader); return(reader); } catch (SqlException e) { logger.Fatal(e, string.Format("Exception while executing spCall{0}{1}", Environment.NewLine, spCall.ToString())); throw; } finally { if (cmd != null) { cmd.Dispose(); } } }