protected PlainSql ( StringBuilder sb ) : void | ||
sb | StringBuilder | |
return | void |
public Exception HandleException(Exception ex, SqlPreCommandSimple command) { var nex = ReplaceException(ex, command); nex.Data["Sql"] = command.PlainSql(); return(nex); }
protected internal override object ExecuteScalar(SqlPreCommandSimple preCommand, CommandType commandType) { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { object result = cmd.ExecuteScalar(); if (result == null || result == DBNull.Value) { return(null); } return(result); } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) { throw; } throw nex; } } }
protected internal override DataSet ExecuteDataSet(SqlPreCommandSimple preCommand, CommandType commandType) { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet result = new DataSet(); da.Fill(result); return(result); } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) { throw; } throw nex; } } }
protected internal override int ExecuteNonQuery(SqlPreCommandSimple preCommand, CommandType commandType) { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { int result = cmd.ExecuteNonQuery(); return(result); } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) { throw; } throw nex; } } }
public void ExecuteDataReaderDependency(SqlPreCommandSimple preCommand, OnChangeEventHandler change, Action reconect, Action <FieldReader> forEach, CommandType commandType) { bool reconected = false; retry: try { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL-Dependency")) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { if (change != null) { SqlDependency dep = new SqlDependency(cmd); dep.OnChange += change; } using (SqlDataReader reader = cmd.ExecuteReader()) { FieldReader fr = new FieldReader(reader); int row = -1; try { while (reader.Read()) { row++; forEach(fr); } } catch (Exception ex) { FieldReaderException fieldEx = fr.CreateFieldReaderException(ex); fieldEx.Command = preCommand; fieldEx.Row = row; throw fieldEx; } } } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) { throw; } throw nex; } } } catch (InvalidOperationException ioe) { if (ioe.Message.Contains("SqlDependency.Start()") && !reconected) { reconect(); reconected = true; goto retry; } throw; } }
public Exception HandleException(Exception ex, SqlPreCommandSimple command) { var nex = ReplaceException(ex, command); nex.Data["Sql"] = command.PlainSql(); return nex; }
protected internal override DataSet ExecuteDataSet(SqlPreCommandSimple preCommand, CommandType commandType) { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet result = new DataSet(); da.Fill(result); return result; } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) throw; throw nex; } } }
public void ExecuteDataReaderDependency(SqlPreCommandSimple preCommand, OnChangeEventHandler change, Action reconect, Action<FieldReader> forEach, CommandType commandType) { bool reconected = false; retry: try { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL-Dependency")) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { if (change != null) { SqlDependency dep = new SqlDependency(cmd); dep.OnChange += change; } using (SqlDataReader reader = cmd.ExecuteReader()) { FieldReader fr = new FieldReader(reader); int row = -1; try { while (reader.Read()) { row++; forEach(fr); } } catch (Exception ex) { FieldReaderException fieldEx = fr.CreateFieldReaderException(ex); fieldEx.Command = preCommand; fieldEx.Row = row; throw fieldEx; } } } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) throw; throw nex; } } } catch (InvalidOperationException ioe) { if (ioe.Message.Contains("SqlDependency.Start()") && !reconected) { reconect(); reconected = true; goto retry; } throw; } }
protected internal override int ExecuteNonQuery(SqlPreCommandSimple preCommand, CommandType commandType) { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { int result = cmd.ExecuteNonQuery(); return result; } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) throw; throw nex; } } }
protected internal override object ExecuteScalar(SqlPreCommandSimple preCommand, CommandType commandType) { using (SqlConnection con = EnsureConnection()) using (SqlCommand cmd = NewCommand(preCommand, con, commandType)) using (HeavyProfiler.Log("SQL", () => preCommand.PlainSql())) { try { object result = cmd.ExecuteScalar(); if (result == null || result == DBNull.Value) return null; return result; } catch (Exception ex) { var nex = HandleException(ex, preCommand); if (nex == ex) throw; throw nex; } } }