无法从 NHibernate.Driver.OracleDataClientDriver 创建驱动程序
这是引发异常的代码:
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保实际的 Oracle 驱动程序位于您的应用程序 bin 文件夹中。
例如,在 Visual Studio 中,您应该在项目中添加对
Oracle.DataAcess.dll
的引用。选择DLL =>右键单击它=>在“属性”网格中,选择“复制本地”= True。
这应该可以解决你的问题。
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.