Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# NHibernate & Oracle Managed Client

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

like image 583
Jan Sršeň Avatar asked Aug 26 '15 14:08

Jan Sršeň


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


1 Answers

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.

like image 126
rshimoda Avatar answered Sep 28 '22 03:09

rshimoda