SQL Server 阻止了對組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪問,openrowset
原因:在從遠程伺服器複製資料到本地時出現
“SQL Server 阻止了對組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪問,因為此組件已作為此伺服器安全配置的一部分而被關閉。系統管理員可以通過使用 sp_configure 啟用 'Ad Hoc Distributed Queries'。有關啟用 'Ad Hoc Distributed Queries' 的詳細資料 ”
錯誤,因此網上搜尋,發現以下解決方案:
啟用Ad Hoc Distributed Queries:
[sql] view plaincopyprint?
- exec sp_configure 'show advanced options',1
- reconfigure
- exec sp_configure 'Ad Hoc Distributed Queries',1
- reconfigure
使用完成後,關閉Ad Hoc Distributed Queries:
[sql] view plaincopyprint?
- exec sp_configure 'Ad Hoc Distributed Queries',0
- reconfigure
- exec sp_configure 'show advanced options',0
- reconfigure
本人驗證成功!
怎啟用與關閉 Ad Hoc Distributed Queries
今天調試公司的程式時,發現了這樣的錯誤
SQL Server 阻止了對組件
'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource'
於是在網上搜尋了一下解決辦法
啟用Ad Hoc Distributed Queries:execsp_configure'show advanced options',1reconfigureexecsp_configure'Ad Hoc Distributed Queries',1reconfigure
關閉Ad Hoc Distributed Queries:execsp_configure'Ad Hoc Distributed Queries',0reconfigureexecsp_configure'show advanced options',0reconfigure
就字面的意思上看,這是一個分散式查詢的服務,在去MSDN上查了一下資料:
預設情況下,SQL Server 不允許使用 OPENROWSET 和 OPENDATASOURCE 進行即席分散式查詢。
此選項設定為 1 時,SQL Server 允許進行即席訪問。
如果此選項未設定或設定為 0,則 SQL Server 不允許進行即席訪問。
即席分散式查詢使用 OPENROWSET 和 OPENDATASOURCE 函數串連到使用 OLE DB 的遠端資料源。
OPENROWSET 和 OPENDATASOURCE 只應在引用不常訪問的 OLE DB 資料來源時使用。
對於將要經常訪問的資料來源,應定義連結的伺服器。
MSDN自然也很給力的給了案例代碼
下面的樣本啟用即席分散式查詢,然後使用OPENROWSET
函數查詢名為Seattle1的伺服器。
sp_configure'show advanced options',1;
RECONFIGURE;sp_configure'Ad Hoc Distributed Queries',1;
RECONFIGURE;GOSELECTa.*FROMOPENROWSET('SQLNCLI','Server=Seattle1;Trusted_Connection=yes;','SELECT GroupName, Name, DepartmentID
FROM AdventureWorks2012.HumanResources.Department
ORDER BY GroupName, Name')ASa;GO
允許使用臨時名稱意味著到 SQL Server 的任何經過身分識別驗證的登入名稱均可訪問該提供者。
SQL Server 管理員應對任何本地登入名稱都能安全訪問的提供者啟用此功能。
SQL Server怎啟用Ad Hoc Distributed Queries?
1、啟用Ad Hoc Distributed Queries的辦法SQL Server 阻攔了對組件""Ad Hoc Distributed Queries"" 的STATEMENT""OpenRowset/OpenDatasource""的接見,因為此組件已作為此辦事器安然裝置的一項目組而被封閉。體系經管員可以經由過程應用。
reconfigure;應用完畢後,記得必然要封閉它,因為這是一個安然隱患,切記履行下面的SQL語句:exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure 2、應用樣本建立連結辦事器 exec s p_addlinkedserver ""ITSV "", "" "", ""SQLOLEDB "", ""長途辦事器名或ip地址 "" exec s p_addlinkedsrvlogin ""ITSV "", ""false "",null, ""使用者名稱 "", ""暗碼 "" 查詢樣本 * ITSV.資料庫名.dbo.表名 匯入樣本 * into 表 ITSV.資料庫名.dbo.表名 今後不再應用時刪除連結辦事器 exec s p_dropserver ""ITSV "", ""droplogins "" 3、串連長途/區域網路資料(openrowset/openquery/opendatasource) 1、openrowset 查詢樣本 * openrowset( ""SQLOLEDB "", ""sql辦事器名 ""; ""使用者名稱 ""; ""暗碼 "",資料庫名.dbo.表名) 產生本地表 * into 表 openrowset( ""SQLOLEDB "", ""sql辦事器名 ""; ""使用者名稱 ""; ""暗碼 "",資料庫名.dbo.表名) 把本地表匯入長途表 openrowset( ""SQLOLEDB "", ""sql辦事器名 ""; ""使用者名稱 ""; ""暗碼 "",資料庫名.dbo.表名) * 本地表 更新本地表 b set b.列A=a.列A openrowset( ""SQLOLEDB &qu......餘下全文>>