(1)查询192.168.1.1的数据库(TT)表test1的数据
select * from opendatasource('sqloledb','server=192.168.1.1;uid=sa;pwd=123456;database=TT').TT.dbo.test1
(2)从192.168.1.2的数据库(TT)表test2插入192.168.1.1数据库(TT)的表test1去
insert into opendatasource('sqloledb','server=192.168.1.1;uid=sa;pwd=123456;database=TT').TT.dbo.test1 (id,[name],password) select id,[name],password
from opendatasource('sqloledb','server=192.168.1.2;uid=sa;pwd=123456;database=TT').TT.dbo.test2
----------------SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问
开启方法:
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO