日期:2014-05-17 浏览次数:20446 次
--启用Ad Hoc Distributed Queries 即可:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
--用完关闭:Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
--#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,port;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]
--关闭选项
EXEC SP_CONFIGURE 'Ad Hoc Distributed Queries',0
RECONFIGURE
EXEC SP_CONFIGURE 'show advanced options',0
RECONFIGURE
GO