日期:2014-05-17 浏览次数:20512 次
--#1.先建立链接服务器后,调用OPENQUERY查询,注意FMTONLY,NOCOUNT选项
SELECT *
FROM OPENQUERY
(
[链接服务器],
'SET FMTONLY OFF;SET NOCOUNT ON; EXEC distribution.sys.sp_MSenum_distribution'
) T
WHERE T.[status] > 4 --1 = 启动;2 = 成功;3 = 正在进行;4 = 空闲;5 = 重试;6 = 失败
ORDER BY [status] DESC
--#2.或者直接调用OPENROWSET查询
--打开高级选项,允许即席查询
EXEC SP_CONFIGURE 'show advanced options',1
RECONFIGURE
EXEC SP_CONFIGURE 'Ad Hoc Distributed Queries',1
RECONFIGURE
GO
SELECT *
FROM OPENROWSET
(
'SQLOLEDB',
'SERVER=127.0.0.1,1433;uid=xx;pwd=xxxxx;Database=master',
'SET FMTONLY OFF;SET NOCOUNT ON; EXEC distribution.sys.sp_MSenum_distribution'
) T
WHERE T.[status] > 4
ORDER BY [status] DESC
--关闭选项
EXEC SP_CONFIGURE 'Ad Hoc Distributed Queries',0
RECONFIGURE
EXEC SP_CONFIGURE 'show advanced options',0
RECONFIGURE
GO