天天看點

SQL Server 阻止了對元件 \'Ad Hoc Distributed Queries\'

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中查詢一下Excel檔案的時候出現問題:

SELECT *  FROM OPENROWSET( 'MICROSOFT.JET.OLEDB.4.0','Excel 8.0;IMEX=1;HDR=YES;DATABASE=D:\a.xls',[sheet1$])

    結果提示:

    SQL Server 阻止了對元件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的通路,因為此元件已作為此伺服器安全配置的一部分而被關閉。系統管理者可以通過使用 sp_configure 啟用 'Ad Hoc Distributed Queries'。有關啟用 'Ad Hoc Distributed Queries' 的詳細資訊,請參閱 SQL Server 聯機叢書中的 "外圍應用配置器"。

查詢相關資料,找到解決方法:

    啟用Ad Hoc Distributed Queries:

exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'Ad Hoc Distributed Queries',1

reconfigure

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

exec sp_configure 'Ad Hoc Distributed Queries',0

reconfigure

exec sp_configure 'show advanced options',0

reconfigure

SELECT   *

FROM      OPENDATASOURCE(

         'SQLOLEDB',

         'Data Source=ServerName;User ID=sa;Password=sa'

         ).DataBaseName.dbo.Table

轉載于:https://www.cnblogs.com/baiefjg/archive/2009/06/13/1502796.html