NHibernate连接Oracle配置问题
2013-04-22 10:37
393 查看
这几天在做NHibernate连接Oracle的测试,配置文件是从NHibernate发行包里拷贝出来的,做了简单的连接字符的修改,配置文件如下:
代码
<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
for your own use before compile tests in VisualStudio.
-->
<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
User ID=xx;Password=xx;Data Source=xx;
</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<mapping assembly="Model"/>
</session-factory>
</hibernate-configuration>
修改了两处内容:
一修改dialect为NHibernate.Dialect.Oracle10gDialect,(我用的是oracle10g)原来的为NHibernate.Dialect.OracleDialect,不修改会提示映射文件不能编译,这个错误有点奇怪。
二增加mapping节点,来指定映射文件所在程序集
好了,简单的写个测试程序,再测试一下,OK测试能过。
我们看到在配置文件中有一行:<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->,这里使用的是微软提供的驱动程序,我们改成Oracle提供的试试。在配置文件中把 NHibernate.Driver.OracleClientDrivern改成 NHibernate.Driver.OracleDataClientDrivern。OK再测试,提示“Could not create the driver from NHibernate.Driver.OracleDataClientDriver.”,应该是我们没有添加Oracle.DataAccess的引用,我们来添加引用,很奇怪在添加程序集的窗口中的.Net选项卡,找不到,没有关系,我们在浏览选项卡里找,在“X:\oracle\product \10.2.0\client_1\BIN”目录下找到并选择Oracle.DataAccess.dll,再来做测试。还是提示“Could not create the driver from NHibernate.Driver.OracleDataClientDriver.”,我们找到Oracle.DataAccess.dll,拷贝到测试程序的bin目录下,再运行。这次还是报错,不过错误提示变了,“Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'.”,上网google了好久,没有找到解决办法,后来看到园友1-2-3在用NHibernate调用Oracle的存储过程 这篇文章找到了解决办法,在配置文件中增加一行:“<property name="hbm2ddl.keywords">none</property>”,再次执行我们的测试程序,这次执行通过。
微软和Oracle都提供了.net连接Oracle数据库的驱动程序,一般认为Oracle所提供的驱动程序性能上要优于微软提供的。在.net4.0中使用System.Data.OracleClient时,会得到警告信息:“'System.Data.OracleClient.OracleConnection' is obsolete: 'OracleConnection has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260' ”,在给出的这个链接上有这么一句话:“The types in System.Data.OracleClient are deprecated. The types are supported in version 4 of the .NET Framework but will be removed in a future release. Microsoft recommends that you use a third-party Oracle provider.”意思是System.Data.OracleClient是不再被推荐使用的,并且在4.0以后的版本将被移除,微软推荐你使用 Oracle提供的驱动程序。
代码
<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
for your own use before compile tests in VisualStudio.
-->
<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
User ID=xx;Password=xx;Data Source=xx;
</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<mapping assembly="Model"/>
</session-factory>
</hibernate-configuration>
修改了两处内容:
一修改dialect为NHibernate.Dialect.Oracle10gDialect,(我用的是oracle10g)原来的为NHibernate.Dialect.OracleDialect,不修改会提示映射文件不能编译,这个错误有点奇怪。
二增加mapping节点,来指定映射文件所在程序集
好了,简单的写个测试程序,再测试一下,OK测试能过。
我们看到在配置文件中有一行:<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->,这里使用的是微软提供的驱动程序,我们改成Oracle提供的试试。在配置文件中把 NHibernate.Driver.OracleClientDrivern改成 NHibernate.Driver.OracleDataClientDrivern。OK再测试,提示“Could not create the driver from NHibernate.Driver.OracleDataClientDriver.”,应该是我们没有添加Oracle.DataAccess的引用,我们来添加引用,很奇怪在添加程序集的窗口中的.Net选项卡,找不到,没有关系,我们在浏览选项卡里找,在“X:\oracle\product \10.2.0\client_1\BIN”目录下找到并选择Oracle.DataAccess.dll,再来做测试。还是提示“Could not create the driver from NHibernate.Driver.OracleDataClientDriver.”,我们找到Oracle.DataAccess.dll,拷贝到测试程序的bin目录下,再运行。这次还是报错,不过错误提示变了,“Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'.”,上网google了好久,没有找到解决办法,后来看到园友1-2-3在用NHibernate调用Oracle的存储过程 这篇文章找到了解决办法,在配置文件中增加一行:“<property name="hbm2ddl.keywords">none</property>”,再次执行我们的测试程序,这次执行通过。
微软和Oracle都提供了.net连接Oracle数据库的驱动程序,一般认为Oracle所提供的驱动程序性能上要优于微软提供的。在.net4.0中使用System.Data.OracleClient时,会得到警告信息:“'System.Data.OracleClient.OracleConnection' is obsolete: 'OracleConnection has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260' ”,在给出的这个链接上有这么一句话:“The types in System.Data.OracleClient are deprecated. The types are supported in version 4 of the .NET Framework but will be removed in a future release. Microsoft recommends that you use a third-party Oracle provider.”意思是System.Data.OracleClient是不再被推荐使用的,并且在4.0以后的版本将被移除,微软推荐你使用 Oracle提供的驱动程序。
相关文章推荐
- NHibernate连接Oracle配置问题
- NHibernate连接Oracle10g配置问题
- 程矢Oracle oracle即时客户端Instant Client连接Oracle同时配置解决乱码问题
- Navicat for Oracle 安装后连接配置问题(ORA-12541或者ORA-28547等)
- oracle客户端免安装配置、64位机器PL/SQL和VS自带的IIS连接问题
- Oracle几个基础配置问题:ORA-12154: TNS: 无法解析指定的连接标识符、ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务、ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序
- Oracle几个基础配置问题:ORA-12154: TNS: 无法解析指定的连接标识符、ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务、ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序
- 也谈windows下cx_Oracle的配置,环境连接乱码种种问题最终解决
- windows下利用navicat连接oracle的一些配置问题总结
- 关于PL SQL Developer连接远程Oracle的配置问题
- secure crt连接oracle 解决oracle账户锁定问题,并配置weblogic数据源
- oracle 配置网络连接常见问题
- windows下利用navicat连接oracle的一些配置问题总结
- Oracle几个基础配置问题:ORA-12154: TNS: 无法解析指定的连接标识符、ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务、ORA-12516 TNS监听程序找
- 老二牛车Oracle oracle即时客户端Instant Client连接Oracle同时配置解决乱码问题
- 实习第2天 环境配置 vs2010 64位系统下连接oracle的问题
- hibernate 配置连接oracle 11g数据库时Dialect的选择问题求教
- 不安装客户端oracle客户端 Nhibernate配置连接oracle数据库
- oracle安装和配置中出现的问题