sql server跨数据库查询,并启动Ad Hoc Distributed Queries

exec sp_configure 'show advanced options',1    --开起
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
Go


SELECT distinct([GoodsCode]) FROM  OPENROWSET('SQLOLEDB','192.168.8.88';'sa';'123456',[Test].[dbo].[Customs]) 

exec sp_configure 'Ad Hoc Distributed Queries',0   --关闭
reconfigure
exec sp_configure 'show advanced options',0
reconfigure

  

原文地址:https://www.cnblogs.com/wangtaobiu/p/13085139.html