Table of SQL Errors & Stored Procedures

I have this bit of code I found on the web 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's writing entries to the myErrors table, but it's not writing an error message or an error severity.

My first question is why?

I believe it's got something to with the error severity being within a certain range.

How can I tell it to log verbose error messages ALWAYS, regardless of severity?

Answers


According to MSDN, ERROR_MESSAGE() etc are only set within the CATCH block of a TRY ... CATCH statement.


Need Your Help

How to clear the cookies and set smsession as loggedoff once logout button click

cookies

I used sencha tool for mobile app and in login tried to open a dynamic restfulweb service page which has created in tomcat 6 server. And when click on logout it will take to main page.

Binding a new SoapClient to a specific IP address before sending outgoing request

c# web-services binding ip-address soap-client

Let's say a machine where the application sits on has SoapClient (to be specific, I'm using Microsoft.Web.Service3.Messaging.SoapClient). It communicates toward a remote location with no problem by