在使用SQL Server數(shù)據(jù)庫(kù)的過(guò)程中,經(jīng)常會(huì)遇到SQL遠(yuǎn)程查詢(xún)的問(wèn)題,下面就教您一個(gè)實(shí)現(xiàn)SQL遠(yuǎn)程查詢(xún)的方法,供您參考。
語(yǔ)句:
select *
from opendatasource('SQLOLEDB','Password=密碼;Persist Security Info=True;User ID=用戶(hù)名;Data Source=數(shù)據(jù)庫(kù)服務(wù)器').數(shù)據(jù)庫(kù).dbo.表名
運(yùn)行后提示錯(cuò)誤:
SQL Server 阻止了對(duì)組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪(fǎng)問(wèn),因?yàn)榇私M件已作為此服務(wù)器安全配置的一部分而被關(guān)閉。系統(tǒng)管理員可以通過(guò)使用 sp_configure 啟用 'Ad Hoc Distributed Queries'。有關(guān)啟用 'Ad Hoc Distributed Queries' 的詳細(xì)信息,請(qǐng)參閱 SQL Server 聯(lián)機(jī)叢書(shū)中的 "外圍應(yīng)用配置器"。
解決:
--啟用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','Password=密碼;Persist Security Info=True;User ID=用戶(hù)名;Data Source=數(shù)據(jù)庫(kù)服務(wù)器').數(shù)據(jù)庫(kù).dbo.表名
-- 使用完成后,關(guān)閉Ad Hoc Distributed Queries:
- exec sp_configure 'Ad Hoc Distributed Queries',0
- reconfigure
- exec sp_configure 'show advanced options',0
- reconfigure
以上就是SQL遠(yuǎn)程查詢(xún)的實(shí)現(xiàn)方法。
該文章在 2011/5/4 17:41:34 編輯過(guò)