Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2008
    Posts
    1

    Unanswered: Exception handling on linked server

    Hi,

    I am trying to handle exceptions using try catch with remote database.

    I am writing the following code which works fine if login locally but when I am trying to do the same on linked server its not being caught in try..catch block. Can anyone help me.

    The procedure I am writing to raiserror
    create proc CustomError
    as
    RAISERROR ('db error', 16, 1);

    I am calling the above procedure in local database using following code

    BEGIN TRY
    exec CustomError
    END TRY
    BEGIN CATCH
    select ERROR_MESSAGE() as ERROR_MESSAGE;
    END CATCH;
    GO

    and it works perfectly. I am able to catch the error in catch block.

    and i m getting the following result
    db error

    but when i am trying to do the same on linked server the code doesn't take me to catch block. I am getting following error while executing the code



    go
    BEGIN TRY
    exec [192.168.0.50].[BM].dbo.CustomError
    END TRY
    BEGIN CATCH
    select ERROR_MESSAGE();
    END CATCH;
    GO

    where [192.168.0.50] is a linked server name and BM is the database name and custom error is my sp which is on remote server.

    its giving me following error

    Msg 50000, Level 16, State 1, Procedure CustomError, Line 11
    db error

    can anyone help me on this.
    Last edited by shirazm; 03-09-09 at 04:38.

  2. #2
    Join Date
    Jul 2012
    Posts
    1

    exception handling on linkserver

    I think this will work:

    BEGIN TRY
    exec('exec [192.168.0.50].[BM].dbo.CustomError')
    END TRY
    BEGIN CATCH
    select ERROR_MESSAGE();
    END CATCH;
    GO

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •