I am making a program in C# that attacks an Oracle 12C database that is in another virtual machine. If I connect using SQL Developer I have no problems, I connect and I can work.
Now I try to enter from code and I get the error indicated in the title of the question The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.
The connection string is as follows:
Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.87)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = PRUEBA)));
User Id=SYSTEM;Password=PASS;
I have tested using version v4.0.30319 of Oracle.DataAccess and also version v2.0.50727.
I have compiled for x86 and for Any CPU.
The database is on a 64-bit WINDOWS SERVER 2012 R2 Standard.
I have verified that there is ping in both directions of the machines.
I'm a bit desperate because I don't know what else to try, if someone can help me I would be very grateful.
PS: The name of the service is not TEST but for security we will do as if it were
Edit 1:
_cnn_string = this.tCadena.Text.ToString();
this._cnn = new OracleConnection(_cnn_string);
try
{
this._cnn.Open();
MessageBox.Show("Conexión correcta!");
}
catch (Exception ex)
{
MessageBox.Show("Error!: " + ex.Message);
}
finally
{ this._cnn.Close(); }
The connection string is put in a bare textbox to do the tests and is as follows:
Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.87)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = PRUEBA)));User Id=SYSTEM;Password=PASS;
Finally I have managed to solve it by changing the Oracle provider, instead of using Oracle.DataAccess.Client I have used Oracle ODP.NET, Managed Driver 12.2.1100 from the page https://www.nuget.org/packages/Oracle.ManagedDataAccess/
Thanks to all for the help