tags:

views:

351

answers:

2

I'm working on an Excel Addin (VSTO) in .NET that connects to an Oracle 10g database.

I'm running on Vista x64 and have figured out that I need both the x86 and x64 Oracle clients installed on my machine so that both 32 bit processes (like PL/SQL Developer) and 64 bit processes (like an example .NET console app compiled for "Any CPU") can connect to Oracle.

That's all working fine. My problem is that Excel is a 32 bit app hosting a .NET DLL and, according to ProcessMonitor the excel process is loading the "OraClient10g_home1" Oracle client at "C:\oracle\product\10.2.0\client_1\BIN\oci.dll" (which happens to be the 64 bit client) and that gives me a BadImageFormatException when my .NET code tries to use it.

What I want is to tell .NET to load the 32 bit "OraClient10g_home2" Oracle client (i.e. "C:\oracle\product\10.2.0\client_2\BIN\oci.dll"). How can I tell .NET to use client_2 instead of client_1.

+2  A: 

Try changing the DllPath in HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME\ODP.NET.

idea
You can change it in the app.config too. http://download.oracle.com/docs/html/E10927_01/InstallODP.htm
Christian13467
This is what I did in the end
d4nt
You say you are using the Microsoft provider for Oracle (System.Data.OracleClient). I am very surprised (to say the least) that setting this parameter that is specific to the Oracle provider (Oracle.DataAccess) should solve your problem.
Mac
+2  A: 

You could :

Mac
That's great. How exactly do I tell .NET to use the instant client?
d4nt
Just ship it along your application : http://stackoverflow.com/questions/70602/what-is-the-minimum-client-footprint-required-to-connect-c-to-an-oracle-database
Mac
That tells me how to package the oracle client, but how do we tell .net to use those DLLs that we've included in our app as opposed to the Full client that is installed on my PC. I don't see how having the instant client in a folder will change what .net uses?
d4nt
Because of the way DLLs are loaded on the Windows platform : the application folder is searched first, then the %PATH%. I'll get you a link as soon as I can (I'm on my phone right now).
Mac
There you go (slightly more complicated that what I said in my previous comment, but that was the spirit of it) : http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx
Mac