Connecting to Oracle DB from .NET/C# - 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

Related

Dll not found error while using monolibusb

I am trying to do a bulk transfer using monolibusb, but whenever I try to run the code, I get the following error.
System.DllNotFoundException: 'libusb-1.0.dll not found. If this is a 64bit operating system, ensure that the 64bit version of libusb-1.0.dll exists in the '\Windows\System32' directory.'
I haven't yet found a solution on the internet that has worked for me. Any help would be appreciated.
I have already tried downloading and copying the dll files into System32 and SysWOW64 and still to no avail.
The dll referenced is not compatible to your operating system or its not found.
Download the zip from source
Extract the contents like below
\MS32\dll\libusb-1.0.dll ---> C:\windows\SysWOW64\
\MS64\dll\libusb-1.0.dll ---> C:\windows\System32\
In production system you can install the dll in Global assembly Cache . Refer here

Oracle.DataAccess.Client Dependencies

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.

Could not load System.Data.SqlServerCe.Entity.dll (Yet it's there)

I have a silverlight application. The server app has an SQL Server CE 4 .sdf in App_Data, and an ADO.NET model generated from it.
If I try to Add->New Item->Domain Service Class, I get the error:
Schema specified is not valid. Errors:
Models.TasksDatabaseMode.ssdl(2,98): error (0004): Could not load
System.Data.SqlServerCe.Entity.dll. Reinstall SQL Server Compact.
However, I installed RIAServices.EntityFramework and EntityFramework.SqlServerCompact via NuGet, which has successfully downloaded this .dll to /packages, and the file has been copied out into the /bin folder. So I have no idea where it is apparently looking for this .dll, if not there.
Perhaps related, I was earlier attempting to have the database generated code-first. However, the Domain Context Wizard was also failing, but with an error about an index being out of bounds. With a manually written service, the build was failing with a MetadataWorkspace error, about which I couldn't find any information.
Does installing the runtime directly (http://www.microsoft.com/en-us/download/details.aspx?id=17876) fix the issue?
Also, what version of the binary are you using? I suspect that you may have the private version (4.0.0.1) and generation is expecting the machine version (4.0.0.0)

Need to load a DLL to use SQLiteWrapper in C#

I am trying to access my databases in C#. The databases are SQLite and I am trying to access it like so:
string CurrentDatabase = Path.FullName + "\\stock.sqlite";
SQLiteBase db = new SQLiteBase(CurrentDatabase);
I am using a SQLite DLL I found here to access the database:
http://www.codeproject.com/KB/database/cs_sqlitewrapper.aspx
But I get this error:
Unable to load DLL 'sqlite3': The
specified module could not be found.
(Exception from HRESULT: 0x8007007E)
I think I know what's wrong, I dont have the sqlite3 DLL anywhere on my system... but I would like this application to be portable so I cannot expect users to already have this DLL installed. I have read about loading a DLL from another application which has already got this DLL somewhere, Firefox is a good example. It's installed on all of my companies machines and if I could some how load the sqlite3 DLL from the Firefox Program Files directory into my application it should work perfectly, no? If that's really the solution I'll need help actually loading the DLL, as I don't know how to do that.
Thanks.
Copy the sqlite3.dll into the same directory where your DLL wrapper is and supply that as part of the distributable of your application when done, in that way there'll be no nonsense associated with dll versioning mismatches.. you can download the latest version from http://sqlite.org
I recommend using System.Data.SQLite, which is an ADO.NET provider for SQLite. Then you can program with the ADO.NET API. Its DLL includes sqlite3.dll, so you don't have to include it.

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