來源:http://www.htmer.com/article/922.htm
今天單位一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查詢編輯器中執行如下語句:
|
1
2
3
4
|
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
|
2.關閉Ad Hoc Distributed Queries組件,在sql查詢編輯器中執行如下語句:
|
1
2
3
4
|
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
|
------------------------------ 前台修改------------------------------
在程序中系統提示:SQL Server 阻止了對組件 ‘ Ad Hoc Distributed Queries ’ 的 STATEMENT ‘ OpenRowset/OpenDatasource ’ 的訪問,因為此組件已作為此服務器安全配置的一部分而被關閉。系統管理員可以通過使用 sp_configure 啟用 ‘ Ad Hoc Distributed Queries ’。有關啟用 ‘ Ad Hoc Distributed Queries ’ 的詳細信息,請參閱SQL Server聯機叢書中的 “ 外圍應用配置器 ”。
1、開始 — 所有程序 — Microsoft SQL Server 2008 R2 — SQL Server Management Studio(如圖1-1)。
2、進入后會彈出窗口【連接到服務器】,在【身份驗證】選擇中【Windows身份驗證】— 點擊【連接】(如圖1-2)。
3、在數據庫服務實例名(如圖1-3,GP-PC\sql2008位置)點擊鼠標右鍵【方面】。
4、在窗口【查看方面】— 點擊【常規】— 【方面】— 選擇【外圍應用配置器】(如圖1-4)。
5、找到【AdHocRemoteQueriesEnabled】— 選擇【True】— 點擊【確定】(如圖1-5)退出后再登錄程序即可。
