SQL Server 阻止了對組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪問,openrowset

來源:互聯網
上載者:User

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?
  1. exec sp_configure 'show advanced options',1  
  2. reconfigure  
  3. exec sp_configure 'Ad Hoc Distributed Queries',1  
  4. reconfigure  



    使用完成後,關閉Ad Hoc Distributed Queries:

[sql] view plaincopyprint?
  1. exec sp_configure 'Ad Hoc Distributed Queries',0  
  2. reconfigure  
  3. exec sp_configure 'show advanced options',0  
  4. 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......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.