How does System.Data.OracleClient finds installed OracleClient - oracle

I wonder how does library System.Data.OracleClient finds installed on machine OracleClient. I've reinstalled the client, but still get error "OracleClient requires Oracle client software", which seem rather suspicious, because client is installed on pc, it has entries in registry and path to oracle client in PATH variable.

This works for me:
Add the environment variable ORACLE_HOME, with the value equal to the base of the install directory (e.g. C:\oracle\product\10.2.0\client_1)
Make sure that %ORACLE_HOME%\bin\ is in the PATH (the setup program should have already put it in there)
Agreed that using ODP.NET is better than deprecated System.Data.OracleClient.

Related

Installing multiple oracle homes on the same machine

I have Oracle 11g installed on my system and want to install 12c now. Read articles ( Oracle docs and general) which suggest that i can do so in different homes.
But when I try to install 12c (12.2.0.1 release 2) , it does not allow me to do so as it says "oracle _home (in environment variables) already defined and does not match the path specified (during installation)".
Am I supposed to specify the paths manually (or change it in the env variables) and if so then how do i accommodate different paths for two Oracle_homes for both versions in the environment variables.
A search on this portal gives results that does not answer my query.
How do I get around the installation?
You should not install more than one (i.e. one each for 32bit and 64bit) Oracle Client on one machine, I could also not imagine any reason for it.
Anyway, if you like to install more than one Oracle Client delete Environment Variable ORACLE_HOME and ORACLE_BASE from your computer, if existing. Then modify PATH Environment Variable and remove all directories of your first Oracle installation from PATH.
After that it should be no problem to install another Oracle Client. You must install it into a different directory, otherwise you mess up the installation and I assume afterwards none of them will work properly.
In order to use one or the other you have to set ORACLE_HOME and PATH Environment Variable accordingly, you cannot use them together! According Managing Oracle Home Directories you should have a "Home Selector" tool but I never used this.
Note, some components (e.g. "Oracle Provider for OLE DB") you can install only once (i.e. one each for 32bit and 64bit). This limitation is caused by Windows COM. Other drivers for example "Oracle Data Provider for .NET" may also fail due to version mismatch and/or policy settings in GAC.

Deploying C# web application connecting to an Oracle database

As we tried to deploy a new project that connects to an Oracle database, we encountered some problems..
On my development workstation, I have my Oracle dll's installed in c:\app\oracle\product\11.2.0\client_1\BIN but on the development web server, it's in stalled in c:\oracle\product\11.2.0\client_1\BIN (noticed NOT in the app folder).
When an application is deployed, those dll's that are referenced need to be in the same location on both machines. So needless to say, we get an error from the development server.
In order to fix this, we tried a few things -
Move the Oracle install to c:\app... on my machine and rebuild from my development machine. This didn't work because there are relative dll's that rely on that path.
Because 1 didn't work, we tried to reset the environment path variables to c:\oracle on my machine. That didn't work.
tried to copy the needed dll's into my bin directory because my understanding is Visual Studio will build from the GAC, then from the bin directory. That didn't work.
Knowing that re-installing Oracle on the development server to c:\app\Oracle isn't an option, has anyone else come across this problem?
You need to make sure that your Oracle install is setup correctly. I have a few utilities that can assist with this.
Step 1 -
The utilities below will confirm first that .net works with Oracle on your server
http://tsells.wordpress.com/2010/02/18/oracle-connection-tester-for-net-applications/
Step 2 -
If the utility above worked - then go to step 3. Otherwise - .net can't see oracle on this machine. Check your path statement first - make sure the oracle bin directory is pointing to is the correct one. If not - change it and try again.
If this doesn't work - I recommend uninstalling oracle completely and reinstalling. Use the following steps.
Stop any services (start - run - services.msc) below that are running
oracle mts recovery
Distributed Transaction Coordinator
Delete all oracle directories from the file system (C:\app, C:\Program Files | C:\Program Files (x86(
Remove Oracle entries from the system path
Remove any Oracle entries from the environment variables (if they exist) such as ORACLE_HOME
Open the registry editor (start -- run -- regedit) and remove any oracle entries from the following key
HKLM\Software\
HKLM\Software\Wow6432Node (64 bit machines only)
Empty Recycle bin (makes me feel better) :)
Reboot the machine
Download one of the two items
Oracle Client Installation (full)
ODAC (Oracle Data Providers)
Install them (make sure if you choose the client version - you use a minimum of the runtime install) - do NOT use the instant client - it never seems to work properly.
Copy the TNSNames.ora file over
Test with the utility again. It should be successful.
Step 3 -
If the utility above worked - then you need to make sure the bit level of your application matches the bit level of the Oracle client installation. For the app - this will be the bit level of the application pool.
Notes - the oracle.dataaccess.dll file in the bin folder is used to help create the images (ngen, aspnet compilation). Once you attempt to call the oracle data provider for .net - it is routed to your client installation to perform the actually data access.

Determing the ORACLE root

I recently installed Oracle Express Edition 10g on my Ubuntu from apt-get. My problem is I dont know exactly in which directory the Oracle resides. I want to set ORACLE_HOME to the path where Oracle has been installed, so that i can create database from terminal. I'd appreciate any help. Thanks
dpkg -L oracle-xe
Will list all the files installed by the oracle-xe package. From that, you should be able to figure out a suitable value for ORACLE_BASE and ORACLE_HOME.
It's possible that the installation has scattered the files around the filesystem, following the usual pattern for Unix applications (eg executables in /usr/bin, libraries in /usr/lib, data in /var/lib/oracle-xe). In that case, there might not be a sensible value for ORACLE_HOME.
According to answers to a very similar question, it seems that the important thing is that ORACLE_HOME points to the location where your static files (code, libraries, and resources) are installed. Something like:
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
I'm not sure how Oracle then knows where to create the database. Hopefully it doesn't just put it in the ORACLE_HOME, because that's in /usr, which should be read-only.

How to tell System.Data.OracleClient to use the 64 bit Oracle Driver

I am trying to run a .NET application which uses System.Data.OracleClient on a Win7 x64 workstation. The workstation has a 32bit Oracle client installed, which leads to the following error message:
Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
So this is my long journey of tries and failures:
I tried to install the Oracle client win64_11gR2_client. But during the setup process it crashes without any comment.
I followed an answer from a different SO thread, tried and extracted the instantclient-basic-windows.x64-11.2.0.2.0, and put the folder containing the binaries in the windows PATH variable. I still get the same error message though (even after rebooting).
I followed the "alternative way" from this answer and copied the files oci.dll, orannzsbb11.dll, and oraociei11.dll into the bin/ folder of my web site project. Still the same error message.
I tried and copied all files from the instant client into that directory and tried again, without success.
I installed ODAC112021Xcopy_x64.zip and put the installation folder and the bin folder in the windows PATH variable. No success.
I put my hope on this answer and reviewed the DllPath in the registry (which is actually supposed to relate to ODP.NET as opposed to System.Data.OracleClient) and saw that DllPath points to the correct x64 installation of ODAC, so, if my application wasn't using System.Data.OracleClient, it should work,b but since it does use that, it still failed.
I googled and stackoverflew but didn't find anything else that the posts I already referred to.
I carefully crafted this SO question in the hope of getting any insightful advice from an enlightened SO user.
After getting the first answer from b_levitt, I tried and added the following lines to the Global.asax at Application_Start:
Environment.SetEnvironmentVariable("ORACLE_HOME", #"C:\OracleProducts\Odac-11.2.0.2.1-x64");
Environment.SetEnvironmentVariable("PATH", #"C:\OracleProducts\Odac-11.2.0.2.1-x64;C:\OracleProducts\Odac-11.2.0.2.1-x64\bin");
C:\OracleProducts\Odac-11.2.0.2.1-x64 is where I installed the ODAC 64 bit xcopy version. No success either.
On a related note, I even tried to force my .NET app into 32bit mode without success, but that's a different thing. I need a forward-looking solution, which means 64bit.
Your #5 should have worked but you also need to set the ORACLE_HOME environment variable. I've done this many times including recently with the very xcopy install that you are using. Please check out my experience with the xcopy install and let me know what kind of additional errors that you get.
In my case I was setting it up for asp.net, but winforms is even easier. You can open a cmd window, use the "set" command to set both the PATH and the ORACLE_HOME environment variables and then run your app from that same cmd window. Once you get the bugs worked out, you can use the Environment.SetEnvironmentVariable to set these within your code.
For the record, I do avoid installing the oracle client on client machines by handling all of the business logic via web services. That way I only need the oracle components on the web server.
I had the same problem you have. I found most of my answers through Oracle forums and here at stackoverflow. I can't post links for reference but I can give you some things to try out.
Also include OraOps11w.dll in your bin directory along with the other Oracle dll files.
Go to the project properties|Reference Paths, add C:\Windows\Microsoft.NET\Framework64\v2.0.50727 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319 to the Reference paths depending on which framework version the project is using.
**Fuzzy part that I don't remember well: Remove the System.Data.OracleClient current reference and add the new reference from C:\Windows\Microsoft.NET\Framework64\v2.0.50727 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319 to the Reference paths depending on which framework version the project is using.
See if the exception goes away.
FYI, Microsoft is dropping Oracle data provider (in ADO.NET) support in the near future. It currently works through .NET 4, but it is a good idea to start testing the native Oracle drivers.

Why doesn't ODP.NET 11 xcopy deployment work on a machine with Oracle DB 10 installed?

I have an app that uses a local version of ODAC 11 below the directory that the .exe file is in. The idea is that we want our app to use the local ODAC 11 regardless of what else the user has installed on her machine.
Oracle.DataAccess.dll is in the same directory as the .exe.
It works fine when the client machine has no Oracle client installed, but I get an error when starting it on a machine with Oracle Database 10.2.0.something installed:
The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.
[Stack Trace]
The provider is not compatible with the version of Oracle client
OracleException
at Oracle.DataAccess.Client.OracleInit.Initialize()
at Oracle.DataAccess.Client.OracleConnection..cctor()
I'm guessing that this has something to do with the runtime binding policy, but a search for "Oracle/ODAC/ODP.NET runtime binding policy" on Google has not turned up anything useful.
Does anyone know how to resolve the issue?
If not this specific issue, can someone point me towards an overview of how to do what I want to do: make sure that my application uses the ODAC 11 no matter what?
So as I understand it, the issue was that while Oracle.DataAccess.dll was in the same directory as the app, it could not find its lower-level homies (oci, et al), hence the compatibility error.
Turns out that if you want an application to work with ODAC 11 xcopy deployment regardless of what else the user may have installed on her machine, you need to do 2 things:
Set the PATH environment variable for the process. (I was already doing this.)
Set the ORACLE_HOME environment variable for the process. (I was not doing this.)
Environment.SetEnvironmentVariable("PATH", Environment.CurrentDirectory + "\\oracle\\11.1\\odac;" + Environment.CurrentDirectory + "\\oracle\\11.1\\odac\\bin;", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("ORACLE_HOME", Environment.CurrentDirectory + "\\oracle\\11.1\\odac", EnvironmentVariableTarget.Process);
EDIT: It's also important to note that Oracle will throw this error not just for environmental issues, but also if one of the files is missing on the target machine. I got this same error on other machines despite the Environment settings because I had Subversion set to ignore directories called "bin", so the OraOps DLL was not being copied to the client.
An article titled "Deploying ODP.NET with Oracle Instant Client" found at http://alderprogs.blogspot.com/2009/04/deploying-odpnet-with-oracle-instant.html gave what was for me about the best explanation of how to deliver a stripped down xcopy type deployment with your application. Only 5 Oracle DLLs required for support.
That said the answers by ObiWanKenobi and Josh Kodroff provides important additional info which matches with my experience.
Add to that: http://www.brothersincode.com/post/Oracle-ODPnet-xcopy-deployment-for-aspnet.aspx
You want to force your ODP.NET drivers to use the copy of oci.dll that is in your local folder, instead of the one already installed.
You can force this by either
setting the PATH variable so the system finds your copy of of oci.dll first (as in the answer by Josh Kodroff)
or
you can use ODP.NET configuration section in app.config (or web.config) to explicitly set the value of "DllPath".
For details, see http://ora-00001.blogspot.com/2010/01/odpnet-minimal-non-intrusive-install.html and http://database.in2p3.fr/doc/oracle/Oracle_Database_11_Release_1_(11.1)_Documentation/win.111/e10927/featConfig.htm
If you're using oracle client 10.2.0.1 or 10.2.0.2, Oracle Note 215255.1 indicates that if you apply patchset 10.2.0.3 it fixes the issue. Get the 10.2.0.3 database patch (852MB) and patch the client home. Yes, it's the full database server patchset, but it applies to the client as well.

Resources