System.InvalidCastException: 无法将类型为“Oracle.DataAccess.Client.OracleConnection”的对象强制转换为类型“System.Data.OracleClient.OracleConnection”。
nhibernate配置文件...
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">5F6A7BD18A9291C0F43F24EC771338FD39658833238D2E36ACE5EE13BAD2F125817C0F77AF436EFF6C85C8AFAA776F5CD7751DB9DFAFD50B</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.OracleDialect</property>
<property name="use_outer_join">true</property>
<mapping assembly="CZTSDM.Domain" />
<mapping assembly="CZTSDM.DAL" />
</session-factory>
</hibernate-configuration>
代码:
/// <summary>
/// session工厂
/// </summary>
private static ISessionFactory _sessionFactory = null;
/// <summary>
/// NHibernate Seesion产生工厂
/// </summary>
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
Configuration cfg = new Configuration();
Configuration myConfiguration = cfg.Configure();
cfg.SetProperty("connection.connection_string", DESEncrypt.Decrypt( cfg.GetProperty("connection.connection_string")));
cfg.SetProperty("hibernate.connection.connection_string", cfg.GetProperty("connection.connection_string"));
_sessionFactory = myConfiguration.BuildSessionFactory();
}
return _sessionFactory;
}
}
/// <summary>
/// 测试连接性
/// </summary>
/// <param name="StrCont"></param>
/// <returns></returns>
private static ISession SessionFactoryByForm(string StrCont)
{
Configuration cfg = new Configuration();
Configuration myConfiguration = cfg.Configure();
cfg.SetProperty("connection.connection_string", StrCont);
cfg.SetProperty("hibernate.connection.connection_string", StrCont);
ISessionFactory psessionFactory = myConfiguration.BuildSessionFactory();
return psessionFactory.OpenSession();
}
如果是用nhibernate的话,楼主代码中应该不会出现和Oracle相关的连接的....
NHibernate 使用 System.Data.OracleClient.dll ,而你使用了 Oracle.DataAccess.dll 。