解決SQL Server 阻止了對組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪問的方法
今天單位一ASP.NET網站,裏面有個功能是導出數據,發現一導出就報錯,報錯內容是:SQL Server 阻止了對組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪問,因爲此組件已作爲此服務器安全配置的一部分而被關閉。系統管理員可以通過使用 sp_configure 啓用 'Ad Hoc Distributed Queries'。有關啓用 'Ad Hoc Distributed Queries' 的詳細信息,請參閱 SQL Server 聯機叢書中的 "外圍應用配置器"。
看錯誤提示就知道是因爲SQL Server的Ad Hoc Distributed Queries組件被禁用了,這裏我用的SQL Server版本是2005,只需要開啓Ad Hoc Distributed Queries就可以了,方法如下:
1.開啓Ad Hoc Distributed Queries組件,在sql查詢編輯器中執行如下語句:
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
2.關閉Ad Hoc Distributed Queries組件,在sql查詢編輯器中執行如下語句:
reconfigure
exec sp_configure 'show advanced options',0
reconfigure