SQL Server 使用OPENROWSET访问ORACLE遇到的各种坑总结
在SQL Server中使用OPENROWSET访问ORACLE数据库时,你可能会遇到各种坑,下面一一梳理一下你会遇到的一些坑。
1:数据库没有开启"Ad Hoc Distributed Queries"选项,那么你就会遇到下面坑。
SELECT TOP 10 * FROM OPENROWSET('OraOLEDB.Oracle', 'ESCM_134';'test';'test', 'SELECT * FROM TEST.MY_SET')
Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online.
出现这个错误,只需要开启数据库"Ad Hoc Distributed Queries"选项即可。如下所示
sp_configure 'show advanced option',1;
GO
RECONFIGURE
sp_configure 'Ad Hoc Distributed Queries',1;
GO
RECONFIGURE
2:遇到“The OLE DB provider "OraOLEDB.Oracle" for linked server ....."这个坑
SELECT TOP 10 * FROM OPENROWSET('OraOLEDB.Oracle', 'ESCM_134';'test';'test', 'SELECT * FROM TEST.MY_SET')
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "OraOLEDB.Oracle" for linked server "(null)" reported an error. Access denied.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "OraOLEDB.Oracle" for linked server "(null)".
解决这个也比较简单,使用SSMS连接到数据库后,在“Server Objects”->"Linked Servers"->"OraOLEDB.Oracle"下勾选“Allow inprocess"选项。注意,如果不重启,无法使之生效,依然会报上面错误。
3:遇到“OLE DB provider "OraOLEDB.Oracle" for linked server "(null)" returned message "ORA-12154: TNS: 无法解析指定的连接标识符...."这个坑
SELECT TOP 10 * FROM OPENROWSET('OraOLEDB.Oracle', 'ESCM_134';'test';'test', 'SELECT * FROM TEST.MY_SET')
OLE DB provider "OraOLEDB.Oracle" for linked server "(null)" returned message "ORA-12154: TNS: 无法解析指定的连接标识符".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "OraOLEDB.Oracle" for linked server "(null)".
遇到这个问题有几种情形:
1: 你没有在TNS配置文件里面配置相关ORACLE实例信息。
2: SQL Server数据库是64位的,你只安装了32bit数据库,配置了Oracle Client 32bit下的TNS,或者Oracle Client 32/64位都安装了,但是你只配置了32位下的TNS。其实只需要配置64下的TNS即可。因为64位的SQL Server肯定调用64位的驱动程序。
4:普通账号遇到“Ad hoc access to OLE DB provider 'OraOLEDB.Oracle' has been denied. You must access this provider through a linked server."错误, 具有sysadmin角色的账号执行下面SQL正常,但是非常普通的账号就一直报下面错误
SELECT TOP 10 * FROM OPENROWSET('OraOLEDB.Oracle', 'ESCM_134';'test';'test', 'SELECT * FROM TEST.MY_SET')
Msg 7415, Level 16, State 1, Line 1
Ad hoc access to OLE DB provider 'OraOLEDB.Oracle' has been denied. You must access this provider through a linked server.
解决方法,在服务器打开注册表,在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.MSSQLSERVER\Providers\OraOLEDB.Oracle下(当然不同版本或命名实例的数据库,这个注册表路径有啥不同,根据实际情况找到OraOLEDB.Oracle),新建DisallowAdHocAccess选项即可解决问题。
DisallowAdHocAccess属性设置为 1,SQL Server 不允许特别通过 OPENROWSET 和 OPENDATASOURCE 函数根据指定的 OLE DB 提供程序访问。如果您尝试调用这些函数中的特殊查询,您会收到类似于以下内容的错误消息
- A change of the value of DisallowAdHocAscess from 1 to 0 would not require a restart of the SQL Service, whereas a change from 0 to 1 would have to have a SQL Service restart for the change that was made to become effective.
- With the DisallowAdHocAccess property set to 1, SQL Server does not allow ad hoc access through the OPENROWSET and the OPENDATASOURCE functions against the specified OLE DB provider. If you try to call these functions in ad hoc queries, you receive an error message that resembles the following:
Server: Msg 7415, Level 16, State 1, Line 1 Ad hoc access to OLE DB provider 'Microsoft.Jet.OLEDB.4.0' has been denied. You must access this provider through a linked server.
In other words, with the DisallowAdHocAccess property set to 1 for a specific OLE DB provider, you must use a predefined linked server setup for the specific OLE DB provider. You can no longer pass in an ad hoc connection string that references that provider to the OPENROWSET or the OPENDATASOURCE function.
参考资料:
https://support.microsoft.com/zh-cn/kb/327489
SQL Server 使用OPENROWSET访问ORACLE遇到的各种坑总结的更多相关文章
- SQL Server数据库转换成oracle
来源:http://blog.csdn.net/hzfu007/article/details/6182151 经常碰到需要把sql server的数据迁移到Oracle的情况. 在网上查找一下,有很 ...
- 使用Microsoft SQL Server Migration Assistant for Oracle迁移数据库
前言:使用Microsoft SQL Server Migration Assistant for Oracle迁移Oracle数据库到SqlServer数据库. 准备:Oracle11g.SqlSe ...
- 使用Apache JMeter对SQL Server、Mysql、Oracle压力测试(四)
这篇文章是对前面三篇的一个总结: 1.从测试结果来看,原生的数据库性能分别是:SQL Server(4587)>Oracle(271)>Mysql(145),测试数据量分别为5W.50W. ...
- SQL Server 跨域访问
# SQL Server 跨服务器访问数据 参考链接: [sp_addlinkedserver](https://msdn.microsoft.com/zh-cn/library/ms190479.a ...
- SQL Server connect to MySQL SQL Server通过LinkServer访问MySQL数据库,并操作mysql数据库代码
SQL Server 中需要访问MySQL的数据,可以通过调用MySQL的ODBC驱动,在SQL Server中添加LinkServer的方式实现. 1.从MySQL网站下载最新的MySQL ODBC ...
- [转]SQL SERVER中openrowset与opendatasource的区别
本文转自:http://blog.sina.com.cn/s/blog_6399df820102vyy8.html SQL SERVER中openrowset与opendatasource的区别: o ...
- SQL server 表结构转Oracle SQL脚本
SQL server 表结构转Oracle SQL脚本 /****** Object: StoredProcedure [dbo].[getOracle] Script Date: 2019/7/25 ...
- SQL Server 2008 R2 链接 Oracle
参考网站: SP_addlinkedserver 小结 (oracle,sql server,access,excel) 64位SqlServer通过链接服务器与32位oracle通讯 SQL Ser ...
- SQL Server 2008 R2 链接 Oracle 10g
首先sqlserver 链接oracle可以通过两个访问接口: “MSDAORA” 和“OraOLEDB.Oracle” 1.“MSDAORA”访问接口是由Microsoft OLE DB Provi ...
随机推荐
- 自定义从Azure下载回来的远程桌面连接(.rdp)文件,使其提供更多丰富功能
通常情况下,我们使用Azure的时候微软会为用户提供可连接管理虚拟机的远程桌面服务,并且支持文件实例的保存,对于Windows 系统来说,微软提供的链接文件实例就是.rdp文件. 获得.rdp文件 打 ...
- ssh整合问题总结--运行项目时报java.lang.StackOverflowError(堆栈溢出)异常
今天在整合ssh项目中,碰到一个异常,当我提交购物车数据到订单时,浏览器报了一个这样的异常. 当时,我就吓坏了.尼玛,这不是内存溢出了吗?吓得我赶紧去检查了每一个有遍历语句的代码,结果没有发现一个死循 ...
- DotNet中几种常用的加密算法
在.NET项目中,我们较多的使用到加密这个操作.因为在现代的项目中,对信息安全的要求越来越高,那么多信息的加密就变得至关重要.现在提供几种常用的加密/解密算法. 1.用于文本和Base64编码文本的互 ...
- 用HTML5 CANVAS做自定义路径的动态效果图片!
最近对HTML5开始感兴趣了,实现的效果如下图,大家可以从代码里换掉图片 我用的是canvas里面的2d绘图,其中上图的路径是网上在线绘制的,我太懒了,哈哈 下面是网址: http://www.vic ...
- 关于Javascript中通过实例对象修改原型对象属性值的问题
Javascript中的数据值有两大类:基本类型的数据值和引用类型的数据值. 基本类型的数据值有5种:null.undefined.number.boolean和string. 引用类型的数据值往大的 ...
- 代码的坏味道(2)——过大的类(Large Class)
坏味道--过大的类(Large Class) 特征 一个类含有过多字段.函数.代码行. 问题原因 类通常一开始很小,但是随着程序的增长而逐渐膨胀. 类似于过长函数,程序员通常觉得在一个现存类中添加新特 ...
- CSS魔法堂:重拾Border之——图片作边框
前言 当CSS3推出border-radius属性时我们是那么欣喜若狂啊,一想到终于不用再添加额外元素来模拟圆角了,但发现border-radius还分水平半径和垂直半径,然后又发现border-t ...
- ASP.NET MVC HtmlHelper之Html.ActionLink
前言 ActionLink用于生成超链接,方法用于指向Controller的Action. 扩展方法与参数说明 ActionLink扩展方法如下: public static MvcHtmlStrin ...
- luogg_java学习_08_设计模式_API
这篇博客总结了1天整,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 , 设计模式 在长期开发过程中,为了解决某些固定问题, 总结出的 ...
- 从零开始学Python第一周:Python基础(上)
Python语法基础(上) 一,Python的变量 (1)创建变量 变量的含义:存储信息的地方 创建变量并赋值 x = 1 print x x = 123 #再次赋值 print x (2)使用变量 ...