检测SQLserver数据库链接是否正常

方法一

select * From [数据库链接名].master.dbo.sysdatabases where name='数据库名' and status<>512

方法二

DECLARE @STATUS VARCHAR(100), @linkedServerName nvarchar(128)
SET @linkedServerName = '数据库链接名';
EXEC @STATUS = sys.sp_testlinkedserver @linkedServerName
IF @STATUS=0--服务器链接正常
BEGIN
PRINT 'success'
END
ELSE
BEGIN
PRINT 'err'
END

原文地址:https://www.cnblogs.com/soulsjie/p/10375225.html