【问题标题】:Could not create the driver from NHibernate.Driver.OracleDataClientDriver无法从 NHibernate.Driver.OracleDataClientDriver 创建驱动程序
【发布时间】:2011-09-02 18:11:33
【问题描述】:

这是引发异常的代码:

public static class NHibernateSessionManager
{
    private static ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();

    public static ISession GetSession(string clientId)
    {
        if (ContextSession == null)
            ContextSession = sessionFactory.OpenSession(new OracleIntercerptor(clientId.ToUpper()));
        else
            ((OracleConnection)ContextSession.Connection).ClientId = clientId;

        return ContextSession;
    }

    // - snip -
}

以及对引发异常的代码的调用:

    private ISession NHibernateSession
    {
        get 
        {
            return NHibernateSessionManager.GetSession(SessionWrapper.GetUser());
        }
    }

我收到TypeInitializationException

{"类型初始化器 'Sigaf.Presupuesto.EntidadesDAL.NHibernate.NHibernateSessionManager' 抛出异常。"}

内部例外

{"无法从 NHibernate.Driver.OracleDataClientDriver。"}

更多内部异常将我引向 NRE:

对象引用未设置为 对象的实例。
在 NHibernate.Driver.OracleDataClientDriver..ctor()

NHibernate v3.0 目标框架 v4.0 此代码实现适用于其他类似的解决方案。

哦,Hibernate.config 文件:

<?xml version="1.0"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
    <property name="current_session_context_class">web</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
    <property name="connection.connection_string_name">Sigaf</property>
    <property name="default_schema">PRE</property>
    <property name="show_sql">true</property>
    <mapping assembly="Sigaf.Presupuesto.EntidadesDAL" />
  </session-factory>
</hibernate-configuration>

【问题讨论】:

    标签: c# oracle nhibernate connection driver


    【解决方案1】:

    确保实际的 Oracle 驱动程序位于您的应用程序 bin 文件夹中。

    例如,在 Visual Studio 中,您应该在项目中添加对 Oracle.DataAcess.dll 的引用。

    选择 DLL => 右键单击​​它 => 在属性网格中选择 Copy Local = True。

    这应该可以解决您的问题。

    【讨论】:

    • 我在我的数据访问项目中这样做了,但没有成功。一旦我在我的应用程序项目 (MVC3) 中执行此操作,它就起作用了。
    • 这是有道理的,一个项目只会引入引用需要编译的程序集。对于这些类型的引用,它们是仅反射/配置引用,它们必须在宿主项目中。
    猜你喜欢
    • 2012-07-28
    • 2011-05-12
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 1970-01-01
    相关资源
    最近更新 更多