protected int ExecuteCommand(SqlProcedureCommand cmd, ICommandResultValidator validator) { try { int value = cmd.Execute(); if (validator.IsValid(value)) { return(value); } string message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, value); if (value == 2) { throw new ArgumentException(message); } throw new System.Exception(message); } catch (SqlException e) { string message; try { message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0); } catch (System.Exception ex) { message = ex.Message; } throw ReportAndTranslateException(e, message); } }
protected List <T> ExecuteListCommand <T>(SqlProcedureCommand cmd, ProcessDataRecordFunction <T> processRecordFunction) { var list = new List <T>(); try { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { list.Add(processRecordFunction(reader)); } } } catch (SqlException e) { string message; try { message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0); } catch (System.Exception ex) { message = ex.Message; } throw ReportAndTranslateException(e, message); } return(list); }
protected void ExecuteReaderCommand(SqlProcedureCommand cmd, ProcessDataRecordAction processRecord) { try { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { processRecord(reader); } } } catch (SqlException e) { string message; try { message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0); } catch (System.Exception ex) { message = ex.Message; } throw ReportAndTranslateException(e, message); } }
protected List <Guid> ExecuteCommandAndReturnGuidArray(SqlProcedureCommand cmd) { var list = new List <Guid>(); try { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { list.Add(reader.GetGuid(0)); } } } catch (SqlException e) { string message; try { message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0); } catch (System.Exception ex) { message = ex.Message; } throw ReportAndTranslateException(e, message); } return(list); }
protected SqlDataReader ExecuteCommandAndReturnReader(SqlProcedureCommand cmd) { try { return(cmd.ExecuteReader()); } catch (SqlException e) { string message; try { message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0); } catch (System.Exception ex) { message = ex.Message; } throw ReportAndTranslateException(e, message); } }
protected string ExecuteCommandAndReturnXmlString(SqlProcedureCommand cmd, string rootLocalName) { try { return(cmd.ExecuteXmlString(rootLocalName)); } catch (SqlException e) { string message; try { message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0); } catch (System.Exception ex) { message = ex.Message; } throw ReportAndTranslateException(e, message); } }
protected byte[] ExecuteCommandAndReturnBinary(SqlProcedureCommand cmd) { try { using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { if (reader.Read()) { var binary = (byte[])reader[0]; if (reader.Read()) { throw new StorageException("Multiple binary rows return. Expected one."); } return(binary); } return(null); } } catch (SqlException e) { string message; try { message = DataDiagnostics.FormatCommandExceptionMessage(cmd.Command, 0); } catch (System.Exception ex) { message = ex.Message; } throw ReportAndTranslateException(e, message); } }