I have developed an application that uses Oracle Data Provider for .NET. I copy the application file (.exe) and ODP library (Oracle.DataAccess.dll) on another computer that Oracle client and ODP.NET are NOT installed on. When I run the application, I got the error msg: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.
*****************Exception Text***************
System.TypeInitializationException: The type initlializer for 'Oracle.DataAccess.Client.OracleConnection at Oracle.DataAccess.Client.OracleConnection..cctor()
--- End of inner exception stack trace ---
at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)
...
Do I have to install ODP.NET and Oracle client on the computer that I want to run my application? If yes, is there other way that I don't have to install them but still can run my application?
Thank you
Easiest Way!!!
- Right click on project and select "Manage NuGet Packages..."
- Search for Oracle.ManagedDataAccess. Install it.
If you are using Entity Framework and your Visual Studio Version is 2012 or higher,then
- Again search for Oracle.ManagedDataAccess.EntityFramework.
Install it.
- Use below name spaces in your .cs file:
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.EntityFramework;
Its done. Now restart your visual studio and build your code.
What do these packages do?
After installing these packages no additional Oracle client software is required to be installed to connect to database.
Both Oracle Data Provider for .NET (from Oracle) and .NET Framework Data Provider for Oracle (from Microsoft) require Oracle Client installed on machine.
Ok, when you know for sure other applications that used the same process worked; on your new application make sure you have the data access reference and the three dll files...
I downloaded ODAC1120320Xcopy_32bit this from the Oracle site:
http://www.oracle.com/technetwork/database/windows/downloads/utilsoft-087491.html
Reference: Oracle.DataAccess.dll (ODAC1120320Xcopy_32bit\odp.net4\odp.net\bin\4\Oracle.DataAccess.dll)
Include these 3 files within your project:
- oci.dll (ODAC1120320Xcopy_32bit\instantclient_11_2\oci.dll)
- oraociei11.dll (ODAC1120320Xcopy_32bit\instantclient_11_2\oraociei11.dll)
- OraOps11w.dll (ODAC1120320Xcopy_32bit\odp.net4\bin\OraOps11w.dll)
When I tried to create another application with the correct reference and files I would receive that error message.
The fix: Highlighted all three of the files and selected "Copy To Output" = Copy if newer. I did copy if newer since one of the dll's is above 100MB and any updates I do will not copy those files again.
I also ran into a registry error, this fixed it.
public void updateRegistryForOracleNLS()
{
RegistryKey oracle = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\ORACLE");
oracle.SetValue("NLS_LANG", "AMERICAN_AMERICA.WE8MSWIN1252");
}
For the Oracle nls_lang list, see this site: https://docs.oracle.com/html/B13804_02/gblsupp.htm
After that, everything worked smooth.
I hope it helps.
Try using Oracle.ManagedDataAccess.dll
You can get it on NuGet (search 'oracle managed') or download ODP.NET_Managed.zip (link is to a beta version, but points you in the right direction)
I use this so that the computers I deploy onto don't need Oracle client installed. N.B. in my opinion this is good for console apps but annoying if you intend to install your application.
You need the oracle client driver installed for those classes to work.
There might be 3rd party connection frameworks out there that can handle Oracle, perhaps someone else might know of some specific ones.
You need an Oracle Client: http://www.oracle.com/technology/oramag/oracle/08-nov/o68odpnet.html
This is an old, but still relevant question, and while the answers here are helpful no one answer fully addressed both of the OP's questions.
1. Do I have to install ODP.NET and Oracle client on the computer that I want to run my application?
YES - if you are using ODP.NET, Unmanaged. This is the version that you typically install when you choose "Oracle Data Provider for .NET" in the Oracle Client installer (for example). You Download this from Oracle (just google it: Oracle URLs change often).
But If you are using ODP.NET, Managed (and you probably want to use this one this instead) then No, you only need to install (or deploy) ODP.NET, Managed with the app, not the full Oracle Client. See below for details.
2. If yes, is there other way that I don't have to install them but still can run my application?
Yes, there is at least one way. And it is the Managed port of ODP.NET.
Unfortunately the usual workarounds, including ODBC, Microsoft's Oracle Provider for .NET (yes, that old, deprecated one), and the ODP.NET, Unmanaged DLL all require the Oracle client to be installed. It wasn't until our friends at Oracle gave us a nice little (~5MB) DLL that is also Managed. This means no more having to depoy 32-bit and 64-bit versions to go with 32-bit and 64-bit Oracle clients! And no more issues with assembly binding where you build against 10.0.2.1 (or whatever) but your customers install a range of clients from 9i all the way to 12c, including the 'g' ones in the middle) because you can just ship it with your app, and manage it via nuget.
But if you use ODP.NET, Managed which is available as a nuget package, then you do not need to install the Oracle Client. You only need the ODP.NET, Managed DLL. And if you were previously using the ODP.NET, Unmanaged DLL, it is very easy to switch: simply change all your references to the Managed ODP.NET (.csproj files in csharp, etc.), and then change any using
statements, for example: using Oracle.DataAccess.Client
becomes using Oracle.ManagedDataAccess.Client
and that's it! (Unless you were supposedly using some of the more advanced DB management features in the full client that are exposed in the ODP.NET, Unmanaged, which I have not done myself, so good luck with that..). And also nuke all of those annoying assemblyBindingRedirect
nodes from your app.config
/web.config
files and never sweat that junk again!
References:
- ODP.NET Details: http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
- ODP.NET is backward and foward-compatible: http://www.oracle.com/technetwork/topics/dotnet/multipledbs-089665.html
- Advanced Configuration: https://docs.oracle.com/cd/E48297_01/doc/win.121/e41125/featConfig.htm
Troubleshooting:
That error typically means ODP.NET was found OK, but Oracle client was not found or not installed. This could also occur when the architecture doesn't match (32-bit Oracle client is installed, but trying to use 64-bit Unmanaged ODP.NET, or vice versa). This can also happen due to permissions issues and path issues and other problems with the app domain (your web app or your EXE or whatever) not being able to find the Oracle DLLs to actually communicate with Oracle over the network (the ODP.NET Unmanaged DLLs are basically just wrappers for this that hook into ADO and stuff).
Common solutions I have found to this problem:
App is 64-bit?
- Install 64-bit Oracle Client (32-bit one wont work)
App is 32-bit?
- Install 32-bit Oracle Client (64-bit one wont work)
Oracle Client is already installed for the correct architecture?
- Verify your environment PATH and
ORACLE_HOME
variables, make sure Oracle can be found (newer versions may use Registry instead) - Verify the ORACLE_HOME and settings in the Registry (And remember: Registry is either 32-bit or 64-bit, so make sure you check the one that matches your app!)
- Verify permissions on the
ORACLE_HOME
folder. If you don't know where this is, check the Registry. I have seen cases where ASP.NET app worker process was using Network Service user and for some reason installing 32-bit and 64-bit clients side by side resulted in the permissions being removed from the first client for theAuthorized Users
group.. fixing perms on the home folder fixed this. - As always, it is handy to Use SysInternals Process Monitor to find out what file is missing or can't be read.
来源:https://stackoverflow.com/questions/914291/the-type-initializer-for-oracle-dataaccess-client-oracleconnection-threw-an-ex