sql 跨库和域插入数据库

php中文网
发布: 2016-06-07 14:59:59
原创
1750人浏览过

sql 跨库和域插入数据库 ; SELECT * INTO [order] FROM OPENROWSET ( 'SQLOLEDB ', '域名'; '用户名'; '密码',数据库名称.表名) 直接执行会报以下错误 SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访

sql 跨库和域插入数据库 ;

SELECT * INTO [order] FROM
OPENROWSET
( 'SQLOLEDB ', '域名'; '用户名'; '密码',数据库名称.表名)

直接执行会报以下错误

SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。

 

解决方法 

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

SELECT * INTO [order] FROM
OPENROWSET
( 'SQLOLEDB ', '域名'; '用户名'; '密码',数据库名称.表名)

 

执行完后

在执行

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' 的详细信息 ”错误,因此网上搜索,发现以下解决方法:

启用Ad Hoc Distributed Queries:

[sql] view plaincopyprint?

 

  1. exec sp_configure 'show advanced options',1  
  2. reconfigure  
  3. exec sp_configure 'Ad Hoc Distributed Queries',1  
  4. reconfigure  



    使用完成后,关闭Ad Hoc Distributed Queries:

[sql] 

 

  1. exec sp_configure 'Ad Hoc Distributed Queries',0  
  2. reconfigure  
  3. exec sp_configure 'show advanced options',0  
  4. reconfigure   

本人验证成功:

后查询SQL联机丛书,MSDN官方为下以内容:

 

默认情况下,SQL Server并不允许专案分布式查询使用OPENROWSET和OPENDATASOURCE。 When this option is set to 1, SQL Server allows ad hoc access.当这个选项被设置为1,SQL Server允许即席访问。 When this option is not set or is set to 0, SQL Server does not allow ad hoc access.当此选项未设置或设置为0,SQL Server不允许即席访问。

Ad hoc distributed queries use the OPENROWSET and OPENDATASOURCE functions to connect to remote data sources that use OLE DB.特设分布式查询使用OPENROWSET和OPENDATASOURCE函数连接到远程数据源,使用OLE DB。 OPENROWSET and OPENDATASOURCE should be used only to reference OLE DB data sources that are accessed infrequently. OPENROWSET和OPENDATASOURCE应该只用于引用OLE DB数据源很少访问。 For any data sources that will be accessed more than several times, define a linked server.将会比多次访问的任何数据源,定义链接服务器。

 Security Note 安全注意事项  
Enabling the use of ad hoc names means that any authenticated login to SQL Server can access the provider.启用使用的专案名称,意味着任何身份验证登录到SQL Server可以访问的供应商。 SQL Server administrators should enable this feature for providers that are safe to be accessed by any local login. SQL Server管理员应该启用此功能为供应商,安全,可以由任何本地登录访问。 For more information, see the DisallowAdhocAccess option in Accessing External Data .欲了解更多信息,请参阅在访问外部数据 的DisallowAdhocAccess选项

 

特此MARK!!!

 

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号