NHibernate连接Oracle10g配置问题


 <!--NHibernate配置-->
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
        <session-factory name="ora10gFactory">
            <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider, NHibernate</property>
            <!--property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property-->
            <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
            <property name="connection.connection_string">
                User ID=fiocoa;Password=fiocoa123;Data Source=ora10g
            </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="current_session_context_class">managed_web</property>
            <property name="proxyfactory.factory_class">NHibernate.Bytecode.DefaultProxyFactoryFactory,NHibernate</property>
            <property name="hbm2ddl.keywords">none</property>
            <!--加载映射-->
            <mapping assembly="Enterprise.Model.Basis"/>
        </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提供的驱动程序。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值