![](/img/trans.png)
[英]Could not create the driver from NHibernate.Driver.OracleDataClientDriver (with copy local set to true)
[英]Could not create the driver from 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:
Object 引用未設置為 object 的實例。
在 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>
確保實際的 Oracle 驅動程序位於您的應用程序 bin 文件夾中。
例如,在 Visual Studio 中,您應該在項目中添加對Oracle.DataAcess.dll
的引用。
Select DLL => 右鍵單擊它 => 在屬性網格中 select Copy Local = True。
這應該可以解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.