SQL and Stored Procedure Error Table
I have this bit of code I found online at the end of each of my stored procedures:
ROLLBACK TRANSACTION
PRINT '-----START: ERROR DETAILS-----'
PRINT ERROR_NUMBER()
PRINT ERROR_SEVERITY()
PRINT ERROR_STATE()
PRINT ERROR_PROCEDURE()
PRINT ERROR_LINE()
PRINT ERROR_MESSAGE()
PRINT '-----END: ERROR DETAILS-----'
DECLARE @prmErrmsg NVARCHAR(4000);
DECLARE @prmErrSvr INT;
SELECT @prmErrmsg = ERROR_MESSAGE()
,@prmErrSvr = ERROR_SEVERITY();
INSERT INTO dbo.myErrors
([ErrorMessage]
,[ErrorSeverity]
,[DateCreated])
VALUES
(@prmErrmsg
,@prmErrSvr
,GetutcDate())
RAISERROR(@prmErrmsg,@prmErrSvr,1)
It writes records to the myErrors table, but does not record the error message or the severity of the error.
My first question is why?
I believe this is due to the severity of the error being in a certain range.
How can I tell it to log verbose error messages ALWAYS regardless of the severity?
0
source to share