执行远程访问数据库语句,在存储过程中怎么写?
---启用Ad Hoc Distributed Queries
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
---执行远程访问数据库语句
select * from OPENDATASOURCE('SQLOLEDB','data source=.;user id=sa;password=7788250').Fuyoo_SpotTransactionsWebCq.dbo.Auction
---使用完成后,关闭Ad Hoc Distributed Queries
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
--第一次的语句
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
go --加了一个go
---第二次的语句,执行远程访问数据库语句
select *
from OPENDATASOURCE('SQLOLEDB','data source=192.168.1.108;user id=sa;password=yupeigu').ggg.dbo.tb
---第三次语句,使用完成后,关闭Ad Hoc Distributed Queries
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure