------------------------------------------------------------
--这段先执行
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
------------------------------------------------------------
--这里写要执行的SQL语句
select *
from opendatasource('SQLOLEDB','server={server};uid={uid};pwd={pwd}').[DataBaseName].dbo.TableName
------------------------------------------------------------
--语句运行完以后执行这段关闭配置
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
------------------------------------------------------------