如何启用Ad Hoc Distributed Queries

eme*_*der 97 sql sql-server-2008

当我OPENROWSET在SQL Server 2000中运行查询时它工作.

但是SQL Server 2008中的相同查询会生成以下错误:

SQL Server阻止访问组件"Ad Hoc Distributed Queries"的STATEMENT"OpenRowset/OpenDatasource",因为此组件已作为此服务器的安全配置的一部分关闭.系统管理员可以使用sp_configure启用"Ad Hoc Distributed Queries"

Has*_*nab 207

以下命令可以帮助您..

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
Run Code Online (Sandbox Code Playgroud)

  • 唯一缺少的是你应该将“显示高级选项”更改回 0 (4认同)

小智 14

您可以检查以下命令

sp_configure 'show advanced options', 1;
RECONFIGURE;
GO  --Added        
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO

SELECT a.*
FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;',
     'SELECT GroupName, Name, DepartmentID
      FROM AdventureWorks2012.HumanResources.Department
      ORDER BY GroupName, Name') AS a;
GO
Run Code Online (Sandbox Code Playgroud)

或者此文档链接

  • 你需要在第一次'RECONFIGURE'之后添加'GO';' 否则它是一个完美的解决方案 (5认同)

Rob*_*ino 5

如果“不支持”对系统目录的临时更新,或者如果您收到“Msg 5808”,那么您将需要像这样配置覆盖:

EXEC sp_configure 'show advanced options', 1
RECONFIGURE with override
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE with override
GO
Run Code Online (Sandbox Code Playgroud)