Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception

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

like image 409
Sambath Prum Avatar asked May 27 '09 06:05

Sambath Prum


2 Answers

Both Oracle Data Provider for .NET (from Oracle) and .NET Framework Data Provider for Oracle (from Microsoft) require Oracle Client installed on machine.

like image 169
Aleris Avatar answered Sep 21 '22 12:09

Aleris


Easiest Way!!!

  1. Right click on project and select "Manage NuGet Packages..."
  2. Search for Oracle.ManagedDataAccess. Install it.

If you are using Entity Framework and your Visual Studio Version is 2012 or higher,then

  1. Again search for Oracle.ManagedDataAccess.EntityFramework. Install it.
  2. 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.

like image 31
Hitsa Avatar answered Sep 21 '22 12:09

Hitsa