April 9, 2010

NHibernate 2.1 throws System.InvalidCastException on Oracle 10g R1 client

Filed under: Development — Tags: , — Darrin Maidlow @ 3:52 pm

When deploying an early build of an up and coming product on a customers machine I came across the following error:

System.InvalidCastException: Unable to cast object of type ‘Oracle.DataAccess.Client.OracleConnection’ to type ‘System.Data.Common.DbConnection’

This was one of those awesome “doesn’t happen on any of my machine” errors.  After some mucking around we determined that the client machine was using the Oracle 10g  R1 client.  The machines and VMs here we used for testing were all running either 11g, or 10g R2.  Doh!

The simple resolution to this was to modify the NHhibernate config and add the following property:

   1: <property name="hbm2ddl.keywords">none</property>

Depending on your underlying databases and mappings this could cause problems with your code project.  Hopefully you’re not using reserved words, or bad Oracle syntax =).

Under the hood, the problem seems to be that the Oracle10gDialect does not provide an implementation of IDataBaseSchema for 10gR1.   Fabio Maulo has provided some sample code and the steps on for your database and submit it to the NHibernate project for inclusion.

May 22, 2009

Finally an Oracle x64 client that works on Vista – AKA Getting Map 2010 x64 running with Oracle…

Filed under: Uncategorized — Tags: , , — Darrin Maidlow @ 4:01 pm

As my legion of dedicated readers know, I’m an 64 Bit zealot.  I would love to see a Windows task manager free of *32.  It keeps me up at night…well not really but, whatever. =) Autodesk recently released – the first native x64 release.  How could I resist installing that?  I had this funny feeling I would regret this decision.  Somehow, somewhere I just knew I would end up in once again.  So I installed Map 2010, started it up and tried to connect to my Oracle server.  You guessed it.  Connection Failed.

The problem is this.   x64 Applications cannot use the x86 driver.  In my previous attempts to get basic Oracle/ODP connectivity on my x64 Vista machine I ended up running the 11g x86 Oracle client.  Today I was back to the Oracle download site – and lookie lookie.  They’ve released an !  2008 is basically Vista so, maybe, just maybe – I thought Oracle will give us some x64 love.  Here are some steps that will help you get running:

First thing is first.  Backup your TNSnames.ora.  Its found in the network\admin folder. 

Next I un-installed the x86 11.1.0.6 client.   Delete the leftovers with windows explorer.

Next download both the 11.1.0.7 client for both x86 and x64 (yes, we need to run with both…)

First I installed the x64 client.  I like to do full runtime installations. 

Next, I copy my backed up tnsnames.ora into the network\admin folder.

Now fire up Map 2010 x64 – connect to Oracle server – Success!  Happy Happy Days.  Unfortunately, fire up (which is still 32 bit) and it fails with an error of “Cannot find OCI.DLL”.  Doh.

So, I go ahead and install the Oracle 11.1.0.7  x86 client.  I install it to the client_2 folder.  Then copy my tnsnames backup into the network\admin folder in the client_2 folder.  Restart Toad, and success!

Now I want to check one last thing.  Last time I was dealing with this fun issue – I had to set my development projects to only run in x86 mode.  So, I fire up my development project and try it out.  Running IIS in x86 mode works.   Running IIS in x64 mode failed..

The ‘MSDAORA’ provider is not registered on the local machine

It seems the Microsoft MSDAORA provider doesn’t exist in x64 – so change your connection to use the Oracle OraOLEDB.Oracle instead and x64 projects run no problem.  It would be perfect to one day get one install that does both x86 and x64 – but for now, I’m content with this setup.

Technorati Tags: ,,

Powered by WordPress