Error Handling Code

  • I am trying to write some link server based SPs and at one step I am checking if the link server exists. due to some limitation, I am bounded to check through Error Message only (yes not through sysserver)

    Here is what I have wrote to handle the error but the problem is that I still receive the main error followed by the custom error message while I just want the Customer error only.

    INSERT INTO #holdDiskDetails EXEC ('[@MonServer].master..' + mycustomproc)

    SELECT @ERR=@@ERROR

    GOTO ERRORHANDLER

    ERRORHANDLER:

    IF @ERR=7202

    PRINT 'Link Server Not Defined. Please Define ' +@MonServer +' As link server'

    -Forum Etiquette: How to post Performance Problems[/url]

    -Forum Etiquette: How to post data/code to get the best help [/url]

  • Have you used try catch in ur custome proc? I believe you shouls be able to avoid error from this proc.

    may be you can paste code of that proc here,if possible and the complete code where you are calling that proc.

    Online Trainer For SQL DBA and Developer @RedBushTechnologies with 18 yrs exp.

  • I given a chance but that has the same problem. Its printing the Custom error after printing the system error.

    -Forum Etiquette: How to post Performance Problems[/url]

    -Forum Etiquette: How to post data/code to get the best help [/url]

  • Assuming that you're using SQL Server 2005 or above since you're posting in the 2005 forum, why not use TRY/CATCH syntax for the error handling? This eliminates messy GO TO syntax and provides a means for actually managing errors as opposed to simply reporting on them. An introductory article is available here[/url].

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey (6/22/2010)


    Assuming that you're using SQL Server 2005 or above since you're posting in the 2005 forum, why not use TRY/CATCH syntax for the error handling? This eliminates messy GO TO syntax and provides a means for actually managing errors as opposed to simply reporting on them. An introductory article is available here[/url].

    This is really a nice article and help me putting my code back to what I was looking for. Thanks for sharing this Article link.

    -Forum Etiquette: How to post Performance Problems[/url]

    -Forum Etiquette: How to post data/code to get the best help [/url]

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

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