SQL 使用 OPENROWSET 出現訊息 SQL Server 已封鎖元件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 之存取

SQL 使用 OPENROWSET 出現訊息 SQL Server 已封鎖元件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 之存取

當TSQL使用 OPENROWSET 會返回以下的錯誤訊息時的權限開放方式。

訊息:

訊息 15281,層級 16,狀態 1,程序 ,行 1
SQL Server 已封鎖元件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 之存取,因為此元件已經由此伺服器的安全性組態關閉。系統管理員可以使用 sp_configure 來啟用 'Ad Hoc Distributed Queries' 的使用。如需有關啟用 'Ad Hoc Distributed Queries' 的詳細資訊,請參閱《SQL Server 線上叢書》中的<介面區組態>(Surface Area Configuration)。

Msg 15281, Level 16, State 1, Procedure , Line 1
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.

處理:

開放 'd Hoc Distributed Queries 的使用權限,開啟資料庫 - Facet

image

image

 

如果你習慣使用指令,則可以使用以下的語法,而開啟的服務對應表,則可以查詢這篇線上說明 組態選項表

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'ad hoc distributed queries', 1;
GO
RECONFIGURE;
GO

透過開啟此Facet的全縣,則可啟動 OPENROWSET  功能,能 XPCmdShellEnable  等相關設定,如上圖所顯示,
也是可透過 Facet 介面 或 語法方式開啟。

參考資料:

了解介面區組態 
在新安裝 SQL Server 的預設組態中,許多功能都不會啟用。為了盡量減少可能會遭受惡意使用者攻擊的功能數目,SQL Server 會選擇性地單獨安裝和啟動主要服務與功能。系統管理員可在安裝期間變更這些預設值,也可以選擇性地啟用或停用 SQL Server 之執行中執行個體的功能。此外,從其他電腦連接時 ...
http://technet.microsoft.com/zh-tw/library/ms161956.aspx

SQL Server 介面區組態 
介面區域縮小是一種停止或停用未使用元件的安全性措施。介面區域縮小可透過提供較少的系統潛在攻擊途徑,以協助增進安全性。
http://technet.microsoft.com/zh-tw/library/ms173748(SQL.90).aspx

當 OLE DB 資料來源不會被經常參考,因而不保證可設定連結伺服器時,您就可以使用特定名稱來做為資料表參考。在 SQL Server 中,您可以使用 OPENROWSET 與 OPENDATASOURCE 函數來提供特定名稱。

http://technet.microsoft.com/zh-tw/library/ms187873(SQL.100).aspx

您也可以使用 sp_configure 預存程序來設定 Database Engine 選項。如需詳細資訊,請參閱<設定伺服器組態選項>。

http://technet.microsoft.com/zh-tw/library/ms189631.aspx