SQL Server Performance

How to catch the db exception in stored procedure

Discussion in 'SQL Server 2005 General Developer Questions' started by sasivashok, Feb 16, 2010.

  1. sasivashok New Member

    Hi,
    I am using Sql Server 2005. I have one doubt. I write procedure for multiple queries.
    BEGIN TRAN
    BEGIN TRY
    query 1
    query 2
    query 3
    COMMIT TRAN

    END TRY
    BEGIN CATCH
    ROLLBACK TRAN

    END CATCH
    Now i am getting error in the query 1 or 2 or 3 . that is data base error For eg autoid parameter is not supplied . How can i catch the error? And what command is used for this one. I need this one very urgent.Hope your's reply.
    Thanks

  2. FrankKalis Moderator

    Any error will jump into the CATCH block and execute the commands you have stated there.
    Check out these articles:
    http://www.sommarskog.se/error-handling-I.html
    http://www.sommarskog.se/error-handling-II.html

Share This Page