Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not create the driver from NHibernate.Driver.OracleDataClientDriver

Here's the code raising the exception:

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 -
}

and the call to the code where the exception is raised:

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

I get a TypeInitializationException

{"The type initializer for 'Sigaf.Presupuesto.EntidadesDAL.NHibernate.NHibernateSessionManager' threw an exception."}

With an inner exception of

{"Could not create the driver from NHibernate.Driver.OracleDataClientDriver."}

A few more inner exceptions lead me to a NRE:

Object reference not set to an instance of an object.
at NHibernate.Driver.OracleDataClientDriver..ctor()

NHibernate v3.0 Target Framework v4.0 This code implementation is working for other, similar, solutions.

Oh, the Hibernate.config file:

<?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>
like image 896
bevacqua Avatar asked May 26 '11 16:05

bevacqua


1 Answers

Make sure the actual Oracle driver is in your application bin folder.

In Visual Studio you should add a reference to Oracle.DataAcess.dll in your project for example.

Select the DLL => Right click it => In the Properties grid select Copy Local = True.

This should solve your problem.

like image 55
Leniel Maccaferri Avatar answered Nov 16 '22 06:11

Leniel Maccaferri