OCIEnvNlsCreate failed with return code -1

"OCIEnvNlsCreate failed with return code -1 but error message text was not available". This was the error that was really anoying my last week. I've had this problem before on one of our servers and this time it showed up in one of my co-workers machine.

Once again Sysinternals came to the rescue. When I used ProcessMonitor to watch the application running I noticed that it couldn't load some of Oracles dlls. The really strange part was that the dlls it was complaining about were from Oracle 10 and the client we were using were from version 11. I then decide to use ProcessExplorer to checkout out application process in order to find out what dlls were really loaded. Imagine my surprise when I saw that the application had the oci.dll from version oracle client 10 running. At some point someone had put a copy of this dll on the windows/system32 folder, and that was the dll that was being loaded instead of the correct one that was in the Oracle install directory.

After we deleted the incorrect dll our program still had the same error. Turns out that the ORACLE_HOME environment variable was not set either. Once we set the variable and restared IIS it was all fine! So, to sum up:

Error:

OCIEnvNlsCreate failed with return code -1 but error message text was not available

Solution:

 1 - Check if the ORACLE_HOME environment variable is set correctly. Here is how to do it.

 2 - Use Process Explorer to check out what versions of Oracle's dlls are loaded. If it's a different version from the version of the client you have installed, remove these incorrect versions from your machine. They may have been there from a previous client installation.

I hope this will help someone else!

Windows 7 x64 and Oracle Client

I installed my Windows 7 x64 this weekend and so far everything is great. Much better than when I was running on Vista.

I thought I had run into my first problem with 7 when was setting up my Oracle connection. I installed the Oracle Client 11g x64 successfully, I could even connect to the database using SqlPlus. My Visual Studio on the other hand disagreed. When I tried to configure a connection to my Oracle server I got the following error:

Exception: 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

This was weird, after all I could connect to the database through SqlPlus, right? The problem is that VS2008 is 32 bit and as such it needs a 32 Oracle Client in order to connect to the db. When I installed the 32 bit client VS was able to connect to the db on the spot. So the only problem I had with Windows 7 so far had nothing to do with Windows 7, in fact you would run into the same situation in any other 64 bit version of Windows.