Oracle.DataAccess.Client Dependencies - c#

First of all, I want to use the Oracle.DataAccess.dll to use OracleBulkCopy.
I want to know all the dlls that I need to be able to read from a database and then perform a bulkcopy in Oracle. Currently, we are using only one dll to perform all the reads from databases, we are using Oracle.ManagedDataAccess.Client. But I can't use it to perform a bulkCopy.
I don't want to install ODP.NET for the users, I want to include the dll directly in the program. So I want to know the minimum required dlls to be able to use the Oracle.DataAccess.dll in 32bit and in 64bit.
I know that there are some old post about this, but it's quiet old and the listed dlls are out of date. I can't event find some of them.
I installed the ODP.net for ODAC12 and I retreived all the listed dlls in this post. I also tried with with this post. The listed dlls are pointing out the version 11.
I made a dummy project that opens a connection, reads a table and bulk it in another table. I copied the listed dlls from the posts in the root of the project and I included Oracle.DataAccess.dll in the project.
When I run my program in 64 bit I get the following error:
Could not load file or assembly 'Oracle.DataAccess, Version=4.121.2.0,
Culture=neutral, PublicKeyToken=89b483f429c47342'
When I run it in 32 bit, I get this error:
Unable to load DLL 'OraOps12.dll': The specified module could not be
found. (Exception from HRESULT: 0x8007007E)"
The dlls that I included are:
oci.dll
ociw32.dll
Oracle.DataAccess.dll
orannzsbb12.dll
oraocci12.dll
oraociei12.dll
OraOps12.dll

I managed to make it work.
Download the good version of the ODAC that will target your project.
For a 32bit project you need to download the ODAC12..._x32.zip (ODAC121021Xcopy_32bit.zip).
For the 64bit project you need to download the ODAC12..._x64.zip
Unzip it in an empty folder depending on the version you want (32bit vs 64bit).
Locate in the instantclient_12_1 folder all the dlls by searching *.dll in the windows search bar. You need to grab:
oci.dll
ociw32.dll
orannzsbb12.dll
oraociei12.dll
oraons.dll
Locate in the odp.net4 or odp.net20 folder depending on your .NET version this two dlls:
OraOps12.dll
Oracle.DataAccess.dll
Copy the those 32bit dlls or 64bit dlls and put them directly in the Output path of your project. For example in C:\...\vsProjects\BulkInsert\BulkInsert\bin\Debug.
Browse Oracle.DataAccess.dll in your project by pointing on the Output path.
UPD: recent versions of the ODP.NET provider (downloaded from here) have "19" suffix instead of "12" in their filenames:
oci.dll
ociw32.dll
orannzsbb19.dll
oraociei19.dll
oraons.dll
OraOps19.dll
Oracle.DataAccess.dll

I experienced similar problem; install oracle data access components (odac ODTwithODAC122010.zip) for solution.

Looks like you did not install the Oracle Instant client (or any other version of Oracle Client). This is a prerequisite for unmanaged ODP.NET provider.
Install the Oracle Instant client and you are fine. Otherwise you will get nothing but trouble.

Related

How to fix Error HRESULT 0x8007007E on windows 10 x64 [duplicate]

I have a dll library with unmanaged C++ API code I need to use in my .NET 4.0 application. But every method I try to load my dll I get an error:
Unable to load DLL 'MyOwn.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I have read and tried several solutions I have found on the internet. Nothing works..
I have tried using following methods:
[DllImport("MyOwn.dll", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs((UnmanagedType.I4))]
public static extern Int32 MyProIni(string DBname, string DBuser_pass,
string WorkDirectory, ref StringBuilder ErrorMessage);
When I tried following this article and when I run this example (from the downloaded code) it runs without a problem (the dll used is in the bin/debug folder)
I have copied my dll (along with all the files the it depends on into my bin folder).
I also tried this approach but got the same error:
[DllImportAttribute(MyOwnLibDllPath, EntryPoint="TMproIni")]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int MyproIni(string DBname, string DBuser_pass,
string WorkDirectory, ref StringBuilder ErrorMessage);
Any suggestions?
From what I remember on Windows the search order for a dll is:
Current Directory
System folder, C:\windows\system32 or c:\windows\SysWOW64 (for 32-bit process on 64-bit box).
Reading from the Path environment variable
In addition I'd check the dependencies of the DLL, the dependency walker provided with Visual Studio can help you out here, it can also be downloaded for free: http://www.dependencywalker.com
You can use the dumpbin tool to find out the required DLL dependencies:
dumpbin /DEPENDENTS my.dll
This will tell you which DLLs your DLL needs to load. Particularly look out for MSVCR*.dll. I have seen your error code occur when the correct Visual C++ Redistributable is not installed.
You can get the "Visual C++ Redistributable Packages for Visual Studio 2013" from the Microsoft website. It installs c:\windows\system32\MSVCR120.dll
In the file name, 120 = 12.0 = Visual Studio 2013.
Be careful that you have the right Visual Studio version (10.0 = VS 10, 11 = VS 2012, 12.0 = VS 2013...) right architecture (x64 or x86) for your DLL's target platform, and also you need to be careful around debug builds. The debug build of a DLL depends on MSVCR120d.dll which is a debug version of the library, which is installed with Visual Studio but not by the Redistributable Package.
The DLL has to be in the bin folder.
In Visual Studio, I add the dll to my project NOT in References, but "Add existing file". Then set the "Copy to Output Directory" Property for the dll to "Copy if newer".
This is a 'kludge' but you could at least use it to sanity-test:
Try hard-coding the path to the DLL in your code
[DllImport(#"C:\\mycompany\\MyDLL.dll")]
Having said that; in my case running dumpbin /DEPENDENTS as suggested by #anthony-hayward, and copying over 32-bit versions of the DLLs listed there into my working directory solved this problem for me.
The message is just a bit misleading, becuase it isn't "my" dll that can't be loaded - it's the dependencies
Try to enter the full-path of the dll.
If it doesn't work, try to copy the dll into the system32 folder.
"Unable to load DLL 'xxx.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" means the file CAN be found BUT it's not able to load it. Try to copy the DLL file to the root folder of your application, some DLL libraries need to be available in the root folder of the application in order for it to work. Or check if there are any other depending DLL files required by it.
"Cannot find DLL 'xxx.dll': ..." means the file CANNOT be found. Try to check the path. For example, [DllImport(#"\Libraries\Folder\xxx.dll")]
Ensure that all dependencies of your own dll are present near the dll, or in System32.
Turn on the fusion logging, see this question for lots of advice on how to do that. Debugging mixed-mode apps loading problems can be a right royal pain. The fusion logging can be a big help.
Make sure you set the Build Platform Target to x86 or x64 so that it is compatible with your DLL - which might be compiled for a 32 bit platform.
There is one very funny thing (and has a technical relevance) which might waste your hours so thought of sharing it here -
I created a console application project ConsoleApplication1 and a class library project ClassLibrary1.
All the code which was making the p/invoke was present in ClassLibrary1.dll. So before debugging the application from visual studio I simply copied the C++ unmanaged assembly (myUnmanagedFunctions.dll) into the \bin\debug\ directory of ClassLibrary1 project so that it can be loaded at run-time by the CLR.
I kept getting the
Unable to load DLL
error for hours. Later on I realized that all such unmanaged assemblies which are to be loaded need to be copied into the \bin\debug directory of the start-up project ConsoleApplication1 which is usually a win form, console or web application.
So please be cautious the Current Directory in the accepted answer actually means Current Directory of main executable from where you application process is starting. Looks like an obvious thing but might not be so at times.
Lesson Learnt - Always place the unamanaged dlls in the same directory as the start-up executable to ensure that it can be found.
I had the same problem when I deployed my application to test PC. The problem was development PC had msvcp110d.dll and msvcr110d.dll but not the test PC.
I added "Visual Studio C++ 11.0 DebugCRT (x86)" merge module in InstalledSheild and it worked. Hope this will be helpful for someone else.
In my case one unmanaged dll was depending on another which was missing. In that case the error will point to the existing dll instead of the missing one which can be really confusing.
That is exactly what had happen in my case. Hope this helps someone else.
If the DLL and the .NET projects are in the same solution and you want to compile and run both every time, you can right click the properties of the .NET project, Build events, then add something like the following to Post-build event command line:
copy $(SolutionDir)Debug\MyOwn.dll .
It's basically a DOS line, and you can tweak based on where your DLL is being built to.
I think your unmanaged library needs a manifest.
Here is how to add it to your binary. and here is why.
In summary, several Redistributable library versions can be installed in your box but only one of them should satisfy your App, and it might not be the default, so you need to tell the system the version your library needs, that's why the manifest.
Setup: 32-bit Windows 7
Context: Installed a PCI-GPIB driver that I was unable to communicate through due to the aforementioned issue.
Short Answer: Reinstall the driver.
Long Answer:
I also used Dependency Walker, which identified several missing dependency modules. Immediately, I thought that it must have been a botched driver installation. I didn't want to check and restore each missing file.
The fact that I was unable to find the uninstaller under Programs and Features of the Control Panel is another indicator of bad installation. I had to manually delete a couple of *.dll in \system32 and registry keys to allow for driver re-installation.
Issue fixed.
The unexpected part was that not all dependency modules were resolved. Nevertheless, the *.dll of interest can now be referenced.
I have come across the same problem, In my case I had two 32 bit pcs.
One with .NET4.5 installed and other one was fresh PC.
my 32-bit cpp dll(Release mode build) was working fine with .NET installed PC but Not with fresh PC where I got the below error
Unable to load DLL 'PrinterSettings.dll': The specified module could not be
found. (Exception from HRESULT: 0x8007007E)
finally,
I just built my project in Debug mode configuration and this time my
cpp dll was working fine.
Also faced the same problem when using unmanaged c/c++ dll file in c# environment.
1.Checked the compatibility of dll with 32bit or 64bit CPU.
2.Checked the correct paths of DLL .bin folder, system32/sysWOW64 , or given path.
3.Checked if PDB(Programme Database) files are missing.This video gives you ans best
undestand about pdb files.
When running 32-bit C/C++ binary code in 64bit system, could arise this because of platform incompatibility. You can change it from Build>Configuration manager.
I faced the same problem when import C++ Dll in .Net Framework +4, I unchecked Project->Properties->Build->Prefer 32-bit and it solved for me.
It has nothing to do with dependencies if you checked all dependencies and you know you got them all, it has nothing to do with the file being in the wrong directory either or incorrect ARGUMENTS passed to dll, the DLL Fails to load using LoadLibrary itself.. you could check the address returned from LoadLibrary is always 0x0000000 (not loaded).
I couldn't figure this error out either it worked fine on Windows 7, but on Windows 10 it doesn't work. I fixed the problem though it had nothing to do with missing dependencies or Runtime redistributable packs.
The problem was I had to pack the DLL with upx and it started working again.
Something with the file being unpacked and compiled on old Windows XP operating system created a bad PE Header or Bad file format or something, but packing it with UPX did the trick works fine now and the DLL got 3x smaller haha.
I got this error for one C++ project in our solution, and only on our buildmaster's machine. The rest of us could build it with no problem.
In our case it was because that particular project had <WindowsTargetPlatformVersion> in the .vcxproj file set to "10.0" vs. "10.0.18362.0" as in all our other C++ projects.
Not specifying the entire SDK version number seems to have allowed MSBuild to choose the newest(?) SDK and associated build tools.
Our buildmaster likely had the remnants of a newer SDK on his machine, and MSBuild was trying to use it (and thus RC.exe was not found).
In any case, bringing up the project's property page and changing Configuration Properties > General > Windows SDK Version to "10.0.18362.0" (or whichever specific version of the SDK you have installed) for all of the project's configurations/platforms did the trick.

Problem using Global Hooks in Windows Forms [duplicate]

I have a dll library with unmanaged C++ API code I need to use in my .NET 4.0 application. But every method I try to load my dll I get an error:
Unable to load DLL 'MyOwn.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I have read and tried several solutions I have found on the internet. Nothing works..
I have tried using following methods:
[DllImport("MyOwn.dll", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs((UnmanagedType.I4))]
public static extern Int32 MyProIni(string DBname, string DBuser_pass,
string WorkDirectory, ref StringBuilder ErrorMessage);
When I tried following this article and when I run this example (from the downloaded code) it runs without a problem (the dll used is in the bin/debug folder)
I have copied my dll (along with all the files the it depends on into my bin folder).
I also tried this approach but got the same error:
[DllImportAttribute(MyOwnLibDllPath, EntryPoint="TMproIni")]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int MyproIni(string DBname, string DBuser_pass,
string WorkDirectory, ref StringBuilder ErrorMessage);
Any suggestions?
From what I remember on Windows the search order for a dll is:
Current Directory
System folder, C:\windows\system32 or c:\windows\SysWOW64 (for 32-bit process on 64-bit box).
Reading from the Path environment variable
In addition I'd check the dependencies of the DLL, the dependency walker provided with Visual Studio can help you out here, it can also be downloaded for free: http://www.dependencywalker.com
You can use the dumpbin tool to find out the required DLL dependencies:
dumpbin /DEPENDENTS my.dll
This will tell you which DLLs your DLL needs to load. Particularly look out for MSVCR*.dll. I have seen your error code occur when the correct Visual C++ Redistributable is not installed.
You can get the "Visual C++ Redistributable Packages for Visual Studio 2013" from the Microsoft website. It installs c:\windows\system32\MSVCR120.dll
In the file name, 120 = 12.0 = Visual Studio 2013.
Be careful that you have the right Visual Studio version (10.0 = VS 10, 11 = VS 2012, 12.0 = VS 2013...) right architecture (x64 or x86) for your DLL's target platform, and also you need to be careful around debug builds. The debug build of a DLL depends on MSVCR120d.dll which is a debug version of the library, which is installed with Visual Studio but not by the Redistributable Package.
The DLL has to be in the bin folder.
In Visual Studio, I add the dll to my project NOT in References, but "Add existing file". Then set the "Copy to Output Directory" Property for the dll to "Copy if newer".
This is a 'kludge' but you could at least use it to sanity-test:
Try hard-coding the path to the DLL in your code
[DllImport(#"C:\\mycompany\\MyDLL.dll")]
Having said that; in my case running dumpbin /DEPENDENTS as suggested by #anthony-hayward, and copying over 32-bit versions of the DLLs listed there into my working directory solved this problem for me.
The message is just a bit misleading, becuase it isn't "my" dll that can't be loaded - it's the dependencies
Try to enter the full-path of the dll.
If it doesn't work, try to copy the dll into the system32 folder.
"Unable to load DLL 'xxx.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" means the file CAN be found BUT it's not able to load it. Try to copy the DLL file to the root folder of your application, some DLL libraries need to be available in the root folder of the application in order for it to work. Or check if there are any other depending DLL files required by it.
"Cannot find DLL 'xxx.dll': ..." means the file CANNOT be found. Try to check the path. For example, [DllImport(#"\Libraries\Folder\xxx.dll")]
Ensure that all dependencies of your own dll are present near the dll, or in System32.
Turn on the fusion logging, see this question for lots of advice on how to do that. Debugging mixed-mode apps loading problems can be a right royal pain. The fusion logging can be a big help.
Make sure you set the Build Platform Target to x86 or x64 so that it is compatible with your DLL - which might be compiled for a 32 bit platform.
There is one very funny thing (and has a technical relevance) which might waste your hours so thought of sharing it here -
I created a console application project ConsoleApplication1 and a class library project ClassLibrary1.
All the code which was making the p/invoke was present in ClassLibrary1.dll. So before debugging the application from visual studio I simply copied the C++ unmanaged assembly (myUnmanagedFunctions.dll) into the \bin\debug\ directory of ClassLibrary1 project so that it can be loaded at run-time by the CLR.
I kept getting the
Unable to load DLL
error for hours. Later on I realized that all such unmanaged assemblies which are to be loaded need to be copied into the \bin\debug directory of the start-up project ConsoleApplication1 which is usually a win form, console or web application.
So please be cautious the Current Directory in the accepted answer actually means Current Directory of main executable from where you application process is starting. Looks like an obvious thing but might not be so at times.
Lesson Learnt - Always place the unamanaged dlls in the same directory as the start-up executable to ensure that it can be found.
I had the same problem when I deployed my application to test PC. The problem was development PC had msvcp110d.dll and msvcr110d.dll but not the test PC.
I added "Visual Studio C++ 11.0 DebugCRT (x86)" merge module in InstalledSheild and it worked. Hope this will be helpful for someone else.
In my case one unmanaged dll was depending on another which was missing. In that case the error will point to the existing dll instead of the missing one which can be really confusing.
That is exactly what had happen in my case. Hope this helps someone else.
If the DLL and the .NET projects are in the same solution and you want to compile and run both every time, you can right click the properties of the .NET project, Build events, then add something like the following to Post-build event command line:
copy $(SolutionDir)Debug\MyOwn.dll .
It's basically a DOS line, and you can tweak based on where your DLL is being built to.
I think your unmanaged library needs a manifest.
Here is how to add it to your binary. and here is why.
In summary, several Redistributable library versions can be installed in your box but only one of them should satisfy your App, and it might not be the default, so you need to tell the system the version your library needs, that's why the manifest.
Setup: 32-bit Windows 7
Context: Installed a PCI-GPIB driver that I was unable to communicate through due to the aforementioned issue.
Short Answer: Reinstall the driver.
Long Answer:
I also used Dependency Walker, which identified several missing dependency modules. Immediately, I thought that it must have been a botched driver installation. I didn't want to check and restore each missing file.
The fact that I was unable to find the uninstaller under Programs and Features of the Control Panel is another indicator of bad installation. I had to manually delete a couple of *.dll in \system32 and registry keys to allow for driver re-installation.
Issue fixed.
The unexpected part was that not all dependency modules were resolved. Nevertheless, the *.dll of interest can now be referenced.
I have come across the same problem, In my case I had two 32 bit pcs.
One with .NET4.5 installed and other one was fresh PC.
my 32-bit cpp dll(Release mode build) was working fine with .NET installed PC but Not with fresh PC where I got the below error
Unable to load DLL 'PrinterSettings.dll': The specified module could not be
found. (Exception from HRESULT: 0x8007007E)
finally,
I just built my project in Debug mode configuration and this time my
cpp dll was working fine.
Also faced the same problem when using unmanaged c/c++ dll file in c# environment.
1.Checked the compatibility of dll with 32bit or 64bit CPU.
2.Checked the correct paths of DLL .bin folder, system32/sysWOW64 , or given path.
3.Checked if PDB(Programme Database) files are missing.This video gives you ans best
undestand about pdb files.
When running 32-bit C/C++ binary code in 64bit system, could arise this because of platform incompatibility. You can change it from Build>Configuration manager.
I faced the same problem when import C++ Dll in .Net Framework +4, I unchecked Project->Properties->Build->Prefer 32-bit and it solved for me.
It has nothing to do with dependencies if you checked all dependencies and you know you got them all, it has nothing to do with the file being in the wrong directory either or incorrect ARGUMENTS passed to dll, the DLL Fails to load using LoadLibrary itself.. you could check the address returned from LoadLibrary is always 0x0000000 (not loaded).
I couldn't figure this error out either it worked fine on Windows 7, but on Windows 10 it doesn't work. I fixed the problem though it had nothing to do with missing dependencies or Runtime redistributable packs.
The problem was I had to pack the DLL with upx and it started working again.
Something with the file being unpacked and compiled on old Windows XP operating system created a bad PE Header or Bad file format or something, but packing it with UPX did the trick works fine now and the DLL got 3x smaller haha.
I got this error for one C++ project in our solution, and only on our buildmaster's machine. The rest of us could build it with no problem.
In our case it was because that particular project had <WindowsTargetPlatformVersion> in the .vcxproj file set to "10.0" vs. "10.0.18362.0" as in all our other C++ projects.
Not specifying the entire SDK version number seems to have allowed MSBuild to choose the newest(?) SDK and associated build tools.
Our buildmaster likely had the remnants of a newer SDK on his machine, and MSBuild was trying to use it (and thus RC.exe was not found).
In any case, bringing up the project's property page and changing Configuration Properties > General > Windows SDK Version to "10.0.18362.0" (or whichever specific version of the SDK you have installed) for all of the project's configurations/platforms did the trick.

Connecting to Oracle DB from .NET/C#

After finding this tutorial, I downloaded and extracted the files needed. But when I try to add their reference I get this error message:
A Reference to '..\oci.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
Any help with this?
You should download and install ODP.NET (Oracle Data Provider for .NET)
http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
For deployment look at the http://www.oracle.com/technetwork/issue-archive/2008/08-nov/o68odpnet-101744.html, but basically is xcopy deployment as V4Vendetta noted
Update: Client application need these dll's (32 bit version):
oci.dll
Oracle.DataAccess.dll
oraociei11.dll
OraOps11w.dll

Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

I have a dll library with unmanaged C++ API code I need to use in my .NET 4.0 application. But every method I try to load my dll I get an error:
Unable to load DLL 'MyOwn.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I have read and tried several solutions I have found on the internet. Nothing works..
I have tried using following methods:
[DllImport("MyOwn.dll", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs((UnmanagedType.I4))]
public static extern Int32 MyProIni(string DBname, string DBuser_pass,
string WorkDirectory, ref StringBuilder ErrorMessage);
When I tried following this article and when I run this example (from the downloaded code) it runs without a problem (the dll used is in the bin/debug folder)
I have copied my dll (along with all the files the it depends on into my bin folder).
I also tried this approach but got the same error:
[DllImportAttribute(MyOwnLibDllPath, EntryPoint="TMproIni")]
[return: MarshalAs(UnmanagedType.I4)]
public static extern int MyproIni(string DBname, string DBuser_pass,
string WorkDirectory, ref StringBuilder ErrorMessage);
Any suggestions?
From what I remember on Windows the search order for a dll is:
Current Directory
System folder, C:\windows\system32 or c:\windows\SysWOW64 (for 32-bit process on 64-bit box).
Reading from the Path environment variable
In addition I'd check the dependencies of the DLL, the dependency walker provided with Visual Studio can help you out here, it can also be downloaded for free: http://www.dependencywalker.com
You can use the dumpbin tool to find out the required DLL dependencies:
dumpbin /DEPENDENTS my.dll
This will tell you which DLLs your DLL needs to load. Particularly look out for MSVCR*.dll. I have seen your error code occur when the correct Visual C++ Redistributable is not installed.
You can get the "Visual C++ Redistributable Packages for Visual Studio 2013" from the Microsoft website. It installs c:\windows\system32\MSVCR120.dll
In the file name, 120 = 12.0 = Visual Studio 2013.
Be careful that you have the right Visual Studio version (10.0 = VS 10, 11 = VS 2012, 12.0 = VS 2013...) right architecture (x64 or x86) for your DLL's target platform, and also you need to be careful around debug builds. The debug build of a DLL depends on MSVCR120d.dll which is a debug version of the library, which is installed with Visual Studio but not by the Redistributable Package.
The DLL has to be in the bin folder.
In Visual Studio, I add the dll to my project NOT in References, but "Add existing file". Then set the "Copy to Output Directory" Property for the dll to "Copy if newer".
This is a 'kludge' but you could at least use it to sanity-test:
Try hard-coding the path to the DLL in your code
[DllImport(#"C:\\mycompany\\MyDLL.dll")]
Having said that; in my case running dumpbin /DEPENDENTS as suggested by #anthony-hayward, and copying over 32-bit versions of the DLLs listed there into my working directory solved this problem for me.
The message is just a bit misleading, becuase it isn't "my" dll that can't be loaded - it's the dependencies
Try to enter the full-path of the dll.
If it doesn't work, try to copy the dll into the system32 folder.
"Unable to load DLL 'xxx.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)" means the file CAN be found BUT it's not able to load it. Try to copy the DLL file to the root folder of your application, some DLL libraries need to be available in the root folder of the application in order for it to work. Or check if there are any other depending DLL files required by it.
"Cannot find DLL 'xxx.dll': ..." means the file CANNOT be found. Try to check the path. For example, [DllImport(#"\Libraries\Folder\xxx.dll")]
Ensure that all dependencies of your own dll are present near the dll, or in System32.
Turn on the fusion logging, see this question for lots of advice on how to do that. Debugging mixed-mode apps loading problems can be a right royal pain. The fusion logging can be a big help.
Make sure you set the Build Platform Target to x86 or x64 so that it is compatible with your DLL - which might be compiled for a 32 bit platform.
There is one very funny thing (and has a technical relevance) which might waste your hours so thought of sharing it here -
I created a console application project ConsoleApplication1 and a class library project ClassLibrary1.
All the code which was making the p/invoke was present in ClassLibrary1.dll. So before debugging the application from visual studio I simply copied the C++ unmanaged assembly (myUnmanagedFunctions.dll) into the \bin\debug\ directory of ClassLibrary1 project so that it can be loaded at run-time by the CLR.
I kept getting the
Unable to load DLL
error for hours. Later on I realized that all such unmanaged assemblies which are to be loaded need to be copied into the \bin\debug directory of the start-up project ConsoleApplication1 which is usually a win form, console or web application.
So please be cautious the Current Directory in the accepted answer actually means Current Directory of main executable from where you application process is starting. Looks like an obvious thing but might not be so at times.
Lesson Learnt - Always place the unamanaged dlls in the same directory as the start-up executable to ensure that it can be found.
I had the same problem when I deployed my application to test PC. The problem was development PC had msvcp110d.dll and msvcr110d.dll but not the test PC.
I added "Visual Studio C++ 11.0 DebugCRT (x86)" merge module in InstalledSheild and it worked. Hope this will be helpful for someone else.
In my case one unmanaged dll was depending on another which was missing. In that case the error will point to the existing dll instead of the missing one which can be really confusing.
That is exactly what had happen in my case. Hope this helps someone else.
If the DLL and the .NET projects are in the same solution and you want to compile and run both every time, you can right click the properties of the .NET project, Build events, then add something like the following to Post-build event command line:
copy $(SolutionDir)Debug\MyOwn.dll .
It's basically a DOS line, and you can tweak based on where your DLL is being built to.
I think your unmanaged library needs a manifest.
Here is how to add it to your binary. and here is why.
In summary, several Redistributable library versions can be installed in your box but only one of them should satisfy your App, and it might not be the default, so you need to tell the system the version your library needs, that's why the manifest.
Setup: 32-bit Windows 7
Context: Installed a PCI-GPIB driver that I was unable to communicate through due to the aforementioned issue.
Short Answer: Reinstall the driver.
Long Answer:
I also used Dependency Walker, which identified several missing dependency modules. Immediately, I thought that it must have been a botched driver installation. I didn't want to check and restore each missing file.
The fact that I was unable to find the uninstaller under Programs and Features of the Control Panel is another indicator of bad installation. I had to manually delete a couple of *.dll in \system32 and registry keys to allow for driver re-installation.
Issue fixed.
The unexpected part was that not all dependency modules were resolved. Nevertheless, the *.dll of interest can now be referenced.
I have come across the same problem, In my case I had two 32 bit pcs.
One with .NET4.5 installed and other one was fresh PC.
my 32-bit cpp dll(Release mode build) was working fine with .NET installed PC but Not with fresh PC where I got the below error
Unable to load DLL 'PrinterSettings.dll': The specified module could not be
found. (Exception from HRESULT: 0x8007007E)
finally,
I just built my project in Debug mode configuration and this time my
cpp dll was working fine.
Also faced the same problem when using unmanaged c/c++ dll file in c# environment.
1.Checked the compatibility of dll with 32bit or 64bit CPU.
2.Checked the correct paths of DLL .bin folder, system32/sysWOW64 , or given path.
3.Checked if PDB(Programme Database) files are missing.This video gives you ans best
undestand about pdb files.
When running 32-bit C/C++ binary code in 64bit system, could arise this because of platform incompatibility. You can change it from Build>Configuration manager.
I faced the same problem when import C++ Dll in .Net Framework +4, I unchecked Project->Properties->Build->Prefer 32-bit and it solved for me.
It has nothing to do with dependencies if you checked all dependencies and you know you got them all, it has nothing to do with the file being in the wrong directory either or incorrect ARGUMENTS passed to dll, the DLL Fails to load using LoadLibrary itself.. you could check the address returned from LoadLibrary is always 0x0000000 (not loaded).
I couldn't figure this error out either it worked fine on Windows 7, but on Windows 10 it doesn't work. I fixed the problem though it had nothing to do with missing dependencies or Runtime redistributable packs.
The problem was I had to pack the DLL with upx and it started working again.
Something with the file being unpacked and compiled on old Windows XP operating system created a bad PE Header or Bad file format or something, but packing it with UPX did the trick works fine now and the DLL got 3x smaller haha.
I got this error for one C++ project in our solution, and only on our buildmaster's machine. The rest of us could build it with no problem.
In our case it was because that particular project had <WindowsTargetPlatformVersion> in the .vcxproj file set to "10.0" vs. "10.0.18362.0" as in all our other C++ projects.
Not specifying the entire SDK version number seems to have allowed MSBuild to choose the newest(?) SDK and associated build tools.
Our buildmaster likely had the remnants of a newer SDK on his machine, and MSBuild was trying to use it (and thus RC.exe was not found).
In any case, bringing up the project's property page and changing Configuration Properties > General > Windows SDK Version to "10.0.18362.0" (or whichever specific version of the SDK you have installed) for all of the project's configurations/platforms did the trick.

The provider is not compatible with the version of Oracle client

I'm trying to use the Oracle ODP.NET 11g (11.1.0.6.20) Instant Client on my ASP.net project as a Data Provider but when I run the aspx page I get a "The provider is not compatible with the version of Oracle client" error message. Any help would be appreciated.
I've referenced the Data Provider in Visual Studio 2005 and the code behind looks like this:
using Oracle.DataAccess.Client;
..
OracleConnection oOracleConn = new OracleConnection();
oOracleConn.ConnectionString =
"Data Source=MyOracleServerName;" +
"Integrated Security=SSPI";
oOracleConn.Open();
//Do Something
oOracleConn.Close();
The error for the page looks like this:
Exception Details: Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client
Source Error:
Line 21:
Line 22:
Line 23: OracleConnection oOracleConn = new OracleConnection();
Line 24: oOracleConn.ConnectionString =
Line 25: "Data Source=MyOracleServerName;" +
[OracleException (0x80004005): The provider is not compatible with the version of Oracle client]
Oracle.DataAccess.Client.OracleInit.Initialize() +494
Oracle.DataAccess.Client.OracleConnection..cctor() +483
Stack Trace:
[TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.]
Oracle.DataAccess.Client.OracleConnection..ctor() +0
Boeing.IVX.Web.RoyTesting.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\CE218C\Desktop\IVX.Net\Web\IVX\RoyTesting.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
I've been looking into this problem further, and you simply need to grab all the appropriate DLL's from the same downloaded version of ODP.Net and put them in the same folder as your Exe file, because ODP.Net is fussy about not mixing version numbers.
I've explained how to do this here: http://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c
Here's the gist of it though:
Download ODP.Net
Unzip the file
Unzip all the JAR's in it
Grab these dll's that were just unzipped:
oci.dll (renamed from 'oci.dll.dbl')
Oracle.DataAccess.dll
oraociicus11.dll
OraOps11w.dll
orannzsbb11.dll
oraocci11.dll
ociw32.dll (renamed from 'ociw32.dll.dbl')
Put all the DLLs in the same folder as your C# Executable
You should "ignore" all the x86/x64 talk here for starters and instead try the ODP.NET Managed Driver (if you are using .Net v4+):
https://www.nuget.org/packages/Oracle.ManagedDataAccess/
https://www.nuget.org/packages/Oracle.ManagedDataAccess.EntityFramework/
Oracle ODP.net Managed vs Unmanaged Driver
Avoid all the "unmanaged" what DLL what architecture issues! :D (about time Oracle).
The NuGet package (also works for 11g):
The old / manual method:
For info on how to convert to using the managed libraries:
First, here is a great code comparison of managed vs unmanaged: http://docs.oracle.com/cd/E51173_01/win.122/e17732/intro005.htm#ODPNT148
Ensure you have downloaded the ODP.NET, Managed Driver Xcopy version only
From the downloaded zip file, copy and paste into your project directory:
Oracle.ManagedDataAccessDTC.dll
Oracle.ManagedDataAccess.dll
Add a reference to Oracle.ManagedDataAccess.dll
Ensure your exe is released (added to Application Folder in VS2010) with both dlls
I only installed the Oracle Data Provider for .NET 2.0 (11.1.0.6.20) and I did not install the Oracle Instant Client (11.1.0.6.0).
I just installed it and the error disappeared!
This can be caused by running a 64bit .NET runtime against a 32bit Oracle client. This can happen if your server you are running the app on it 64 bit. It will run the .NET app with the 64bit runtime. You can set the CPU flag on your project in VS to run in the 32bit runtime.
Let's make some kind of summary:
Error message "The provider is not compatible with the version of Oracle client" can be caused by several reasons. Meanwhile the error message can have different flavors, e.g. "Object reference not set to an instance of an object." or "Could not load file or assembly 'Oracle.DataAccess,' or one of its dependencies"
You have no Oracle Client installed. In this case the error message is indeed misleading.
Oracle Data Provider for .NET (ODP.NET, i.e. file Oracle.DataAccess.dll) is not included in Oracle Instant Client, it has to be installed separately (download from 32-bit Oracle Data Access Components (ODAC) or 64-bit Oracle Data Access Components (ODAC) Downloads) or you have to select according option in Oracle Universal Installer (OUI).
Note, when installing the Oracle Data Provider >= 12.1, then the provider is not automatically registered into GAC. You have to register it manually if needed, see Oracle Doc 2272241.1.
The version of ODP.NET does not match installed version of Oracle Client. You have to check even the minor version number! For example, Oracle.DataAccess.dll Version 4.112.3.0 is not compatible with Oracle Client 11.2.0.4. Check versions of ODP.NET and Oracle Client carefully. You can use sigcheck on oraociei*.dll and/or OraOps*w.dll to get version of Oracle Client.
Be aware of different numbering scheme. File version 4.112.3.0 means: .NET Framework Version 4, Oracle Release 11.2.0.3.x.
There are ODP.NET version "1.x", "2.x" and "4.x". These numbers are related to Microsoft .NET Framework versions 1.0.3705/1.1.4322, 2.0.50727 and 4.0.30319. Version "1.x" was available until Oracle Client 11.1. Version "4.x" was introduced with Oracle Client 11.2
The architecture (32bit or 64bit) of ODP.NET does not match your application architecture. A 32bit application works only with 32bit Oracle Client/ODP.NET respectively a 64bit application requires 64bit Oracle Client/ODP.NET. (Unless you use ODP.NET Managed Driver)
The .NET Framework version do not match. For example, if you compile your application with Target .NET Framework 2.0 then you cannot use ODP.NET version 4.x. The .NET Framework target version must be equal or higher than version of ODP.NET.
The version of Oracle.DataAccess.dll on your development machine (i.e. the version which is loaded while compiling) is higher than the version on the target machine.
Be aware that Oracle.DataAccess.dll might be loaded from GAC which by default takes precedence over any locally provided file.
Newer release of ODP.NET requires higher Microsoft .NET Framework version. For example ODP.NET version 21.4 requires .NET Framework 4.8. Check the System Requirements in the "Data Provider for .NET Developer's Guide" of your release.
Solutions
Consider to use the ODP.NET Managed Driver, it can be downloaded from Oracle page: 64-bit Oracle Data Access Components (ODAC) Downloads.
There you only have to copy Oracle.ManagedDataAccess.dll file to your application directory, nothing else is required. It works for both 32bit and 64bit.
In your *.csproj, resp. *.vbproj edit your reference to ODP.NET like this:
<Reference Include="Oracle.DataAccess">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
Attributes like Version=... or processorArchitecture=... are not required. Your application will load the correct Oracle.DataAccess.dll depending on selected architecture and target .NET framework (provided that it is installed properly)
-> not 100% verified
In case you do not know the version of Oracle Client on target machine (e.g. it might be the machine of your customer): Go to the download page mentioned above and download the least XCopy version of Oracle Data Access Components. Extract the zip and copy just the Oracle.DataAccess.dll file to your local machine. In your VS project make a reference to this (most likely outdated) DLL. The version of this DLL is the least version of ODP.NET your application will work with. When you run your application then the Publisher Policy in GAC will redirect to actually installed version.
I don't think it is a smart approach to take single DLL's and copy them to certain folders. It may work on a "naked" machine but if your target machine has installed any Oracle products there is a high risk for version mismatch. Uninstall any Oracle products from your machine and make a fresh installation. Have a look at How to uninstall / completely remove Oracle 11g (client)? it order to get a really clean machine.
In case you have to work with 32bit and 64bit applications at the same time, follow this instruction to install both versions on one machine:
Assumptions: Oracle Home is called OraClient11g_home1, Client Version is 11gR2.
Optionally remove any installed Oracle client
Download and install Oracle x86 Client, for example into C:\Oracle\11.2\Client_x86
Download and install Oracle x64 Client into different folder, for example to C:\Oracle\11.2\Client_x64
Open command line tool, go to folder %WINDIR%\System32, typically C:\Windows\System32 and create a symbolic link ora112 to folder C:\Oracle\11.2\Client_x64 (see below)
Change to folder %WINDIR%\SysWOW64, typically C:\Windows\SysWOW64 and create a symbolic link ora112 to folder C:\Oracle\11.2\Client_x86, (see below)
Modify the PATH environment variable, replace all entries like C:\Oracle\11.2\Client_x86 and C:\Oracle\11.2\Client_x64 by C:\Windows\System32\ora112, respective their \bin subfolder. Note: C:\Windows\SysWOW64\ora112 must not be in PATH environment.
If needed set yor ORACLE_HOME environment variable to C:\Windows\System32\ora112
Open your Registry Editor. Set Registry value HKLM\Software\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112
Set Registry value HKLM\Software\Wow6432Node\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112 (not C:\Windows\SysWOW64\ora112)
You are done! Now you can use x86 and x64 Oracle client seamless together, i.e. an x86 application will load the x86 libraries, an x64 application loads the x64 libraries without any further modification on your system.
Commands to create symbolic links:
cd C:\Windows\System32
mklink /d ora112 C:\Oracle\11.2\Client_x64
cd C:\Windows\SysWOW64
mklink /d ora112 C:\Oracle\11.2\Client_x86
Some notes:
Both symbolic links must have the same name, e.g. ora112.
In case you want to install ODP.NET manually afterwards, take care to select appropriate folders for installation.
Despite of their names folder C:\Windows\System32 contains the x64 libraries, whereas C:\Windows\SysWOW64 contains the x86 (32-bit) libraries. Don't be confused.
Maybe it is a wise option to set your TNS_ADMIN environment variable (resp. TNS_ADMIN entries in Registry) to a common location, for example TNS_ADMIN=C:\Oracle\Common\network.
After several hours of troubleshooting, I found this issue to be caused by having Oracle.DataAccess.dll (v4.0) in my projects bin directory, but the runtime also loading Oracle.DataAccess.dll (v2.x) from the GAC. Removing and readding the Oracle.DataAccess entry in the project references solved the problem for me.
The other files mentioned here did not appear to be necessary in my situation.
UPDATE
The root cause of the "The provider is not compatible with the version of Oracle client" error is (generally) that the managed assembly is attempting to load unmanaged libraries which do not match versions. It appears you can force the Oracle driver to use the correct libraries by specifying the library path in the web.config1
<configuration>
<oracle.dataaccess.client>
<settings>
<add name="DllPath" value="C:\oracle\bin"/>
<!-- ... -->
</settings>
</oracle.dataaccess.client>
</configuration>
install ODP.Net on the target machine and it should solve the issue... copying the dll's does not look a good idea...
For Oracle 11g (11.1.0.7.20) I had to add the following dlls along with my Exe to work.
oci.dll
OraOps11w.dll
oraociicus11.dll (pretty huge close to 30mb)
Oracle.DataAccess.dll
It would seem to me that though you have ODP with the Oracle Istant Client, the ODP may be trying to use the actual Oracle Client instead. Do you have a standard Oracle client installed on the machine as well? I recall Oracle being quite picky about when it came to multiple clients on the same machine.
i have the same problem but in my case i can't just copy the dlls into the bin folder, then i only 'rebind' the assembly version.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342" culture="neutral"/>
<bindingRedirect oldVersion="2.112.2.0" newVersion="2.112.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Here's what I did to solve this problem that persisted for 3 long hours:
Under Oracle home located at C:\oracle\product\11.2.0 I had a folder called client_1 where I had previously installed ODP.NET bits for Windows 64 bits.
Later while trying to debug my ASP.NET Web API app with Visual Studio 2012, I kept getting this error message: The provider is not compatible with the version of Oracle client.
Searching Google I found that this was happening because I was using ODP.NET 64 bits. Then I grabbed ODP.NET for Windows 32 bits and installed it but I kept getting the same error message.
SOLUTION: deleted the folder client_1 and resinstalled ODP.NET 32 bits. Somewhat the installer was mixing bits from the 64 bit version with the 32 bit version. Go figure...
Now I'm happy again and I can open a new OracleConnection. FINALLY! :)
TLDR Version:
Use the 12c 100% managed provider instead.
If you must use the old provider, you need to point Oracle.DataAccess.dll to the unmanaged Oracle Client Dlls that are of the correct version. If you have multiple Oracle Clients installed on your machine that maybe a simple as including the "DllPath" configuration variable (see below) in you app config, but you may also need to install a new oracle client to point to.
Full version:
First, lets make sure we understand the components of the old unmnaged provider (not the new 12c 100% managed provider). It's made up of two pieces:
the managed .net component - Oracle.DataAccess.dll
the unmanaged (non-.net) client
Simply speaking, Oracle.DataAccess.dll is nearly just a wrapper, translating .net instructions into ORACLE-NET instructions for the unmanaged client.
That said, when you load Oracle.DataAccess there is a order in which it tries to locate the unmanaged client dlls that it needs. From the Oracle Documentation:
The Oracle.DataAccess.dll searches for dependent unmanaged DLLs (such
as Oracle Client) based on the following order:
1.Directory of the application or executable.
2.DllPath setting specified by application config or web.config.
3.DllPath setting specified by machine.config.
4.DllPath setting specified by the Windows Registry.
HKEY_LOCAL_MACHINE\Software\Oracle\ODP.NET\version\DllPath
5.Directories specified by the Windows PATH environment variable.
So in your case, your app followed this process above and found a path that has unmananged dlls that are too old relative to the Oracle.DataAccess.dll assembly that you are using.
It could just be that the only Oracle Client install on that machine is too old. But this comes into play if you have more than one client installed on the machine and the unmananaged files were found first in a different but older installation. If the later, the simple thing to do is use the dllPath configuration variable in your config and point it at the correct Oracle Home Bin folder:
<configuration>
<oracle.dataaccess.client>
<add key="DllPath" value="c:\oracle\product\1.1.0-xcopy-dep\BIN"/>
</oracle.dataaccess.client>
</configuration>
If you want to install a fresh copy of the client, the xcopy version is the smallest and contains the "instant client" and point the DllPath above to this new location. But any oracle client install will work.
But if you want to avoid all this unmanaged client resolution stuff, see if you can update your app to use the 100% managed provider instead - it truely is just one or two managed assemblies,without any dependency on unmananged files.
Its also possible that you aren't loading the Oracle.DataAccess.dll that you think you are if it is installed in both your bin directory and your GAC, but I think that is the less likely senario. See the assembly resolution process for more information.
Does the IIS/IWAM user have permissions on the Oracle directory? Can you connect to this data source using another app, such as Excel or Access?
I had the exact same problem. I deleted (and forgot that I had deleted) oraociei11.dll after compiling the application. And it was giving this error while trying to execute. So when it cant find the dll that oraociei11.dll, it shows this error. There may be other cases when it gives this error, but this seems to be one of them.
Also look for IIS Application pool Enable 32-bit true or false flag, when you see this message, some oracle forum directed me for this!
For anyone still having this problem: based on this article
http://oradim.blogspot.com/2009/09/odpnet-provider-is-not-compatible-with.html
I found out that my server was missing the Microsoft C++ Visual Runtime Library - I had it on my dev machine because of the Visual Studio installed. I downloaded and installed the (currently) most recent version of the library from here:
http://www.microsoft.com/en-us/download/details.aspx?id=13523
Ran the setup and the oracle call from C# made it!
I didn't go down the road of getting new DLL's. We had a bunch of existing projects that work perfectly fine and it was only my new project that was giving me headache so I decided to try something else.
My project was using an internally developed Internal.dll that depended on Oracle.DataAccess.dll v4.112.3.0. For some reason, when publishing, Visual Studio always uploaded v4.121.0.0, even though it wasn't explicitly specified in any of the config files. That's why I was getting an error.
So what I did was:
Copied Internal.dll from one of the successfully running projects to my web site's /bin (just to be on the safe side).
Copied Oracle.DataAccess.dll from one of the successfully running projects to my web site's /bin.
Add Reference to both of them from my web site.
Finally Oracle.DataAccess reference showed up in myWebSite.csproj, but it showed the wrong version: v4.121.0.0 instead of v4.112.3.0.
I manually changed the reference in myWebSite.csproj, so it now read:
<Reference Include="Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Oracle.DataAccess.dll</HintPath>
</Reference>
This issue could by happen while using unmanaged oracle reference if you have more than one oracle client , or sometimes if you reference different version
There is two way to solve it :
First and fast solution is to remove unmanaged reference and use the managed one from NuGet see this before to go with this option Differences between the ODP.NET Managed Driver and Unmanaged Driver
Second solution is to fix project unmanaged target version like the below :
First Check oracle project reference version (from project references/(dependencies > assemblies ) > Oracle.DataAccess right click > properties):
Then check oracle GAC version
got to gac from run (Win+R) "%windir%\Microsoft.NET\assembly"
Check the platform that matches with you project platform
to check you target platform (right click on your project > properties)
From gac folder search to Oracle.DataAccess
Right Click on Oracle.DataAccess > properties > details and check version
if you notice the versions are different this is an the issue and to fix it we need to redirect assembly version (in startup project go to config file and add the below section )
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.121.2.0" />
</dependentAssembly>
</assemblyBinding>
like this
oldVersion : should be cover your project version
newVersion : GAC version
publicKeyToken : From GAC
We had the same problem, because the Oracle.Data.dll assembly on a network share was updated by our DBA's. Removing the reference from the project, and adding it again solved the problem.
Just two steps to solve this issue.
go to advance setting of application pool and set 'Enable 32 bit Application' flag to True.
Make sure all Dlls in your Bin is 32 bit version now...
best of luck.
Recently I had to work on an older project where the solution and all contained projects were targeted to x32 platform. I kept on trying to copy Oracle.DataAccess.dll and all other suggested Oracle files on all the places, but hit the wall every time. Finally the bulb in the head lit up (after 8 hours :)), and asked to check for the installed ODAC assemblies and their platform. I had all the 64-bit (x64) ODAC clients installed already but not the 32 bit ones (x32). Installed the 32-bit ODAC and the problem disappeared.
How to check the version of installed ODAC: Look in folder C:\Windows\assembly. The "Processor Architecture" property will inform the platform of installed ODAC.
Eight hours is a long time for the bulb to light up. No wonder I always have to slog at work :).
I encountered this problem after I installed Oracle Data Tools for Visual Studio 2015, and then fighting with Oracle for a good hour. I decided to try reinstalling Oracle client again instead of this mess with file copying, config changes, etc., and that worked for me.
I faced a similar issue and the root cause was that GAC had 2 oracle.dataaccess versions i.e. v4.0_4.112.2.0 and v4.0_4.112.4.0 . My application was referring to v4.0_4.112.2.0 , so when I removed v4.0_4.112.4.0 from GAC, it worked fine.
GAC path : C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess
Before :
After :
To remove a version, one can simply delete the corresponding folder from GAC.
On a 64-bit machine, copy "msvcr71.dll" from C:\Windows\SysWOW64 to
the bin directory for your application.
On a 32-bit machine, copy "msvcr71.dll" from C:\Windows\System32 to
the bin directory for your application.
http://randomdevtips.blogspot.com/2012/06/provider-is-not-compatible-with-version.html
Chris' solution worked for me as well. I did however get a follow error message that states:
Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Apparently, in the foreign language of Oraclish, that means that your program are either targeting all platforms, or 32-bit machines.
Simply change your target platform in Project Properties to 64-bit and hope for the best.
I had the same issue with Oracle.DataAccess.dll v4.121.2.0. with 2- homes installation (32 and 64 bit versions). 32-bit version workerd, 64-bit version didn't.
In my case (after 2 days of trying) I found that the problem was permissions on the 64-bit-home version. Many Directories in that version had exclusively overridden permissions where "Authenticated Users" role did not have "Read" access, which is set by default on the parent directory. Those sub-directories included "bin", "network/admin", "nls", "oracore", "RDBMS" and possibly others. I found them by filtering out "ACCESS DENIED" result in "Process Monitor" (Procmon.exe) utility from sysinternals. Once the permissions were inherited from the parent directory to those child subdirectories everything started to work.
I didn't what to override the permissions on the whole oracle home so I did them one directory at a time, but I guess if you don't worry about security so much you can reset it on the whole corresponding oracle home directory.
Lots of theoretical answers here, but here comes a working example with code that you can copy and paste and test immediately:
I installed the Oracle Express database OracleXE112 which already comes with some preinstalled demo tables.
When you start the installer you are asked for a password. I entered "xxx" as password. (not used in production)
My server runs on the machine 192.168.1.158
On the server you must explicitely allow access for the process TNSLSNR.exe in the Windows Firewall. This process listens on port 1521. If you get a timeout error from the below code check your firewall.
OPTION A: For C# (.NET2 or .NET4) you can download ODAC11, from which you have to add Oracle.DataAccess.dll to your project. Additionally this DLL depends on: OraOps11w.dll, oci.dll, oraociei11.dll (130MB!), msvcr80.dll.
These DLLs must be in the same directory as the EXE or you must specify the DLL path in: HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.112.4.0\DllPath. On 64 bit machines write additionally to HKLM\SOFTWARE\Wow6432Node\Oracle\...
OPTION B: If you have downloaded ODAC12 you need Oracle.DataAccess.dll, OraOps12w.dll, oci.dll, oraociei12.dll (160MB!), oraons.dll, msvcr100.dll. The Registry path is HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.121.2.0\DllPath
OPTION C: If you don't want huge DLL's of more than 100 MB you should download ODP.NET_Managed12.x.x.x.xxxxx.zip in which you find Oracle.ManagedDataAccess.dll which is only 4 MB and is a pure managed DLL which works in 32 bit and 64 bit processes as well and depends on no other DLL and does not require any registry entries.
The following C# code works for me without any configuration on the server side (just the default installation):
using Oracle.DataAccess.Client;
or
using Oracle.ManagedDataAccess.Client;
....
string oradb = "Data Source=(DESCRIPTION="
+ "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.158)(PORT=1521)))"
+ "(CONNECT_DATA=(SERVER=DEDICATED)));"
+ "User Id=SYSTEM;Password=xxx;";
using (OracleConnection conn = new OracleConnection(oradb))
{
conn.Open();
using (OracleCommand cmd = new OracleCommand())
{
cmd.Connection = conn;
cmd.CommandText = "select TABLESPACE_NAME from DBA_DATA_FILES";
using (OracleDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
listBox.Items.Add(dr["TABLESPACE_NAME"]);
}
}
}
}

Categories

Resources