Test to See if Linked Server is Available

The following code snippet shows how you can use the sp_testlinkedserver procedure to determine whether a linked server is available:

BEGIN TRY 
    EXEC sp_testlinkedserver N'linked_server_name'; 
END TRY 
BEGIN CATCH 
    PRINT 'Linked Server not available'; 
    ROLLBACK; 
    RETURN; 
END CATCH 
 
-- continue with usage of linked server

See the following links for further discussion of this issue:

How do I prevent linked server errors?
Test linked server connection settings…

Leave a Reply

Your email address will not be published. Required fields are marked *