Help me on Trigger Error Handling..

  • I am using the following Trigger on my appln.Here my problem is ,whenever i get any error (including contraints,null,any error) should be captured and displayed for my customized message.

    Pls help me on this...

    CREATE TRIGGER test_trigger ON dbo.testmydata

    after INSERT

    AS

    DECLARE @CONFIRM INT

    begin

    if (@@ERROR <> 0) goto ErrorHandler

    update qry....

    if (@@ERROR <> 0) goto ErrorHandler

    BEGIN

    EXEC @CONFIRM=master.dbo. xp_sendmail @recipients 'sd@dhd.com',@subject ='Premises Alert Message',@message = 'sdsd'

    END

    if (@@ERROR <> 0) goto ErrorHandler

    ErrorHandler:

    RAISERROR ('An error occured while executing the trigger.',16,2)

    end

    This is the Generating two message -one is from system and another is my message.I dont want to display the system message.any error occurs mesage should be displayed my custom message.

    -Thanx

  • This was removed by the editor as SPAM

  • If you are getting a second message i would check to make sure you don't have an alert setup to trap for that message or the job isn't set to send out emails on failure. Other than that I don't see any issues.

    Wes

  • I think it depends on the severity of the error, some of the errors abort and rollback the transaction and it will be difficult to trap in SQL. Can't you trap/look at the error returned to your app, if its not your known error returned then you will have to do the job yourself.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply