9

I have a big project that conceals another 16 project (Tests, Webs & App like Core, Email etc:.). I use C# MVC4 for my main website project. If I use a non Managed Client need me to do a project folder /bin recorded library Oracle.DataAccess.dll and everything works fine ( I must set(change) in Web.config -> param:

<connectionStrings>
   <add name="PC13" connectionString="User Id=TEST; Password=TEST; Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DBTEST)(PORT=1521))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME = DBTEST)));" />   
</connectionStrings>

And DB connection works fine without ORA exception TNS_NAME ). I must set Data source to full path with tnsnames.ora when I use only alias like TEST i get a message "Exception: ORA-12154: TNS:could not resolve the connect identifier specified", but if i set full tns code for alias -> all works great.

I use hibernate.cfg.xml file:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
   <session-factory>
      <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
      <property name="show_sql">true</property>
      <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
      <property name="command_timeout">60</property>
      <property name="cache.provider_class">NHibernate.Caches.SysCache2.SysCacheProvider, NHibernate.Caches.SysCache2</property>
      <property name="cache.use_second_level_cache">true</property>
      <property name="cache.use_query_cache">true</property>
      <property name="cache.default_expiration">120</property>
   </session-factory>  

My Web.config file (for managed client add oracle.manageddataaccess.client part):

<connectionStrings>
   <add name="PC13" connectionString="User Id=TEST; Password=TEST; Data Source=DBTEST;" />   
</connectionStrings>

<oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="DBTEST" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DBTEST)(PORT=1521))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME = DBTEST)))"/>
      </dataSources>
    </version>
</oracle.manageddataaccess.client>

I have dedicated DB server & I programming on Visual Studio 2010 SP1 32bit (Win 7 64b). I have installed Oracle client 11g (32 & 64b version). File hibernate.cfg.xml is is used in another 3 project in package like "IntegrationTest", "Core" etc:. I run program (F5) with Debug mode and x86 platform.

In project I use:

  • NHibernate v. 3.3.1.4000
  • StructureMap v. 2.6.4.
  • and other unimportant Packages

What do I have to install the package and how to set it up? I Try add reference with Nuget

  • Official Oracle ODP.NET, Managed Driver 12.1.22
  • Oracle Data Provider for .NET (ODP... 121.1.2

When I install some of these packages (add references from Nuget) to my Website project and i change hibernate.cfg.xml to:

<property name="connection.driver_class">NHibernate.Driver.OracleManagedDriver</property>

I got message from VS Exception "Could not create the driver from NHibernate.Driver.OracleManagedDriver"


If i go to the View -> Server Exploler -> to the Data Cennection and i set a Add Connection . . . (see link -> An Easy Drive to .NET Manual) . I dont get a ODP.NET Managed option, only .NET Framework data provider for Oracle option, and when I try connection i get this message "BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed"

My question is

  1. What can I use for reference (driver) ?
  2. How can I set it ?

An Easy Drive to .NET Manual

Thanks a lot

Jan Sršeň
  • 1,045
  • 3
  • 23
  • 46
  • 1
    OracleManagedDriver was added in NHibernate 4.0. It is missing from 3.4 and previous ones. – jahav Aug 27 '15 at 15:20
  • I update to NHibernate 4.0.4., but i still got a message "Could not create the driver from NHibernate.Driver.OracleManagedDriver" and in View -> Server Exploler -> to the Data Connection and i set a Add Connection . . . i dont see ODP.NET Managed Oracle Client Option, How can i find name of **connection.driver_class** from nhibernate.cfg.xml file, i try few several sets like NHibernateOracleExample.Driver.OracleDriver, NHibernateOracleExample or NHibernate.Driver.OracleDataClientDriver but i dont know what is a right name for this setting value – Jan Sršeň Aug 28 '15 at 13:22

1 Answers1

16

I am using NHibernate 4.0.4 and I have installed the "Oracle.ManagedDataAccess" nuget package (https://www.nuget.org/packages/Oracle.ManagedDataAccess/).

In order to configure NHibernate to use the Oracle Managed Driver it is necessary to change just a tad bit the hibernate.cfg.xml file - and use the NHibernate.Driver.OracleManagedDataClientDriver as the "connection.driver_class".

Therefore, my xml config file is as it follows:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.driver_class">NHibernate.Driver.OracleManagedDataClientDriver</property>
    <property name="connection.connection_string">User Id=user;Password=pws;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.10.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=SRV)))</property>
    <property name="show_sql">true</property>
    <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
  </session-factory>
</hibernate-configuration>

Good luck - I know that using Oracle and ORM can be quite an annoying experience, but one that is worth the effort in the end.

rshimoda
  • 1,137
  • 1
  • 13
  • 24
  • Thanks. Its Work great! I have a package which in itself includuje 16 projects(8 testing project), and some projects have an old version of NHibernate (3.xx) with the transition to NHibernate (4.3). Enough to update, add mapping functionality to ForEach, which was in the older version of the library NHibernate and everything else works great. – Jan Sršeň Sep 03 '15 at 07:17
  • Hey, could you take a look at my question? http://stackoverflow.com/questions/37701372/invalidcastexception-reading-number-from-oracle-using-oracle-manageddataaccess-w – Julius Jun 08 '16 at 12:37
  • I tried with "Oracle.ManagedDataAccess" package but it doesn't work for me. When I build the sessionfactory it throw "invalid username/password" message. – bernnabe Mar 13 '18 at 13:45
  • @rshimoda Thank you so much, you are a right modern gentleman. – MarkyMarksFunkyBunch Apr 02 '18 at 14:54