ERROR_MESSAGE() not returning RaiseError's message
I'm running a stored procedure (SQL Server 2005) that's doing an Insert Into a table.
The table has a trigger that is using RaiseError because a value is invalid.
The problem:
When I run the stored proc directly in the Management Studio
it returns a "canned" SQL error message in the Messages window,
plus the errmsg from the trigger's RaiseError.
This is great because it give me nice detail.
But, I want to capture that error info in a table to send to myself.
So, I added
BEGIN TRY
-- code
END TRY
BEGIN CATCH
-- get all the error info
END CATCH
However, the ERROR_MESSAGES() function only returns the canned SQL msg,
NOT the msg from the trigger's RaiseError.
So, now I've lost the detail.
Any idea how I can get the triger's error?
I don't own the trigger, so edting that isn't an option.
Thanks, DaveBo
Re: ERROR_MESSAGE() not returning RaiseError's message
What does your catch look like?
-tg
Re: ERROR_MESSAGE() not returning RaiseError's message
Code:
BEGIN CATCH
INSERT INTO AA_ErrorLog (
ErrSource, ErrLine, ErrNum, ErrMsg, Az_ID, Last_Name, First_Name)
VALUES(
ERROR_PROCEDURE(), ERROR_LINE(), ERROR_NUMBER(), ERROR_MESSAGE(),
IsNull(@AZ_ID,'NULL'), IsNull(@LastName,'NULL'), IsNull(@FirstName,'NULL') )
END CATCH