예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
 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);
     }
 }
예제 #6
0
 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);
     }
 }
예제 #7
0
        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);
            }
        }