Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何启用即席分布式查询_Sql_Sql Server 2008 - Fatal编程技术网

Sql 如何启用即席分布式查询

Sql 如何启用即席分布式查询,sql,sql-server-2008,Sql,Sql Server 2008,当我在SQLServer2000中使用OPENROWSET运行查询时,它会工作 但SQL Server 2008中的同一查询会生成以下错误: SQL Server阻止访问组件“即席分布式查询”的语句“OpenRowset/OpenDatasource”,因为此组件作为此服务器安全配置的一部分已关闭。系统管理员可以通过使用sp\u configure启用“即席分布式查询” 以下命令可能对您有所帮助 EXEC sp_configure 'show advanced options', 1 RECON

当我在SQLServer2000中使用
OPENROWSET
运行查询时,它会工作

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

SQL Server阻止访问组件“即席分布式查询”的语句“OpenRowset/OpenDatasource”,因为此组件作为此服务器安全配置的一部分已关闭。系统管理员可以通过使用sp\u configure启用“即席分布式查询”


以下命令可能对您有所帮助

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

您可以检查以下命令

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

或者此

如果系统目录的临时更新“不受支持”,或者如果您收到“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

顺便说一句,您最好留意警告,并将SQL代码更改为使用链接服务器而不是OPENROWSET。@rbaryYoung这不是真正的“警告”-只是一个通知,说明它未启用。启用此选项有什么危险?如果恶意用户能够在某处注入SQL,启用此选项可能会允许他们探测自己选择的数据文件。如果将其设置为链接服务器,则只有特定的文件(链接服务器)才会公开(并且您可以使用集成的SQL Server安全性,等等)。但我确实喜欢将此选项用于内部测试和数据迁移。。。因此,您需要在第一个“重新配置”之后添加一个“GO;”否则,这是一个完美的解决方案。您不需要在选择之前链接服务器吗?您不需要逐行查看。唯一缺少的是您应该将“显示高级选项”更改回0
EXEC sp_configure 'show advanced options', 1
RECONFIGURE with override
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE with override
GO