Use SYS. sp_testlinkedserver to test whether the linked server connection is normal.

Source: Internet
Author: User

In the forum, I saw a question asking if I could use a T-SQL to test whether the connection to the linked server is normal, so that when I access multiple linked servers, if one of the connections fails, I can skip and not handle it.

 

In sqlserver 2005 and later versions, a system stored procedure is provided"Sp_testlinkedserver"Can be used to test whether the Communications Server is connected. This stored procedure uses linked
The server name is used as the input parameter. The return value 0 indicates success, and 1 indicates failure.

 

The following is a test code:

 

Declare
@ Srvr nvarchar (128 ),
@ Retval int;

Set @ srvr
= 'Mydomainservername ';

Begin try

Exec
@ Retval = SYS. sp_test1_server @ srvr;

End try

Begin catch

Set
@ Retval = Sign (@ error );

End catch;

If @ retval
<> 0

Raiserror ('unable to connect toserver. This operation will be tried later! ', 16,
2 );

 

The following error occurs after running on my machine:

 

MSG 50000, level 16, state 2, line 11

Unable toconnect to server. This operation will be tried later!

 

For more information, see:

Testlinked server connection settings

Sp_testlinkedserver

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.