When I raise more than one error in a stored procedure, like this:
Code: Select all
CREATE PROCEDURE dbo.MultipleErrors
AS
BEGIN
RAISERROR('First error', 16, 1)
RAISERROR('Second error', 16, 1)
RAISERROR('Third error', 16, 1)
END
Code: Select all
Msg 50000, Level 16, State 1, Procedure MultipleErrors, Line 4
First error
Msg 50000, Level 16, State 1, Procedure MultipleErrors, Line 5
Second error
Msg 50000, Level 16, State 1, Procedure MultipleErrors, Line 6
Third error
Code: Select all
SQL Error Code: 50000
First Error
- Where is the extra error information like Level, State, Procedure name and line?
- Where are the "Second error" and "Third" Error"?
Is this a DBExpress problem or something DevArt can fix?
Note: This example looks a bit silly, but in a pre-DBExpress era I have used multiple errors with nested procedure calls. Every calling procedure raised an error when the called procedure returned with a value 0 to indicate that there was an error. There were no try/catch blocks used. Eventually, the Delphi application would get an exception with all error messages combined. With this super-exception message you had a kind of "call stack" which made it easier to track problems.
Edit:
While testing this issue I noticed something else. When I PRINT text in the stored procedure, like this:
Code: Select all
CREATE PROCEDURE dbo.MultipleErrors
AS
BEGIN
PRINT 'First Print'
PRINT 'Second Print'
PRINT 'Third Print'
RAISERROR('First error', 16, 1)
RAISERROR('Second error', 16, 1)
RAISERROR('Third error', 16, 1)
END;
Code: Select all
First Print
Second Print
Third Print
Msg 50000, Level 16, State 1, Procedure MultipleErrors, Line 7
First error
Msg 50000, Level 16, State 1, Procedure MultipleErrors, Line 8
Second error
Msg 50000, Level 16, State 1, Procedure MultipleErrors, Line 9
Third error
Code: Select all
SQL Error Code: 0
First Error
Third Print
Second Print
First Print
- Why are the PRINTs in the exception?
- Why is the SQL Error Code 0 in stead of 50000?
- Why are the PRINTs and Error in reversed order?
Again, this could be a problem of DBExpress. When I use the Embarcadero drivers (D2010 - XE2) I get this:
Code: Select all
SQL State: 42000, SQL Error Code 50000
First Error
SQL State: 01000, SQL Error Code: 0
Third Print
SQL State: 01000, SQL Error Code: 0
Second Print
SQL State: 01000, SQL Error Code: 0
First Print
- Prints are a part of the exception, but have a special sql state
- Prints and exceptions are in reversed order
- But exception still has it's SQL Error Code 50000
Thanks in advance for your time and any solutions/tips you can offer me