Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

oracle

When I try to connect to an Oracle database in my C# application and I try to click a button I get this error:

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

My code for accessing the database:

        static string column;
        static string OracleServer = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=something)(HOST=something)(PORT=something)) (CONNECT_DATA=(SERVICE_NAME=name)));User Id=something;Password=something;";

        public void read()
        {
            try
            {
                var conn = new OracleConnection(OracleServer);
                conn.Open();
                OracleCommand cmd = new OracleCommand("select * from t1", conn);
                OracleDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    var column1 = reader["vermogen"];
                    column = (column1.ToString());
                    listBox1.Items.Add(column);
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

Now I am using the reference Oracle.DataAccess and as code: using Oracle.DataAccess.Client;

The application is an arcgis add in application, and I converted it to a form application and it does connect to the database. But I have to have it work in the add in application.

I have never experienced this error and I am not experienced at Oracle databases and I was wondering what is causing this error? When I run the application, I dont get any errors. But when I click the buttons of the User Interface of the application, I get this error.

What should I do to lose the error and what is causing it?

like image 681
Loko Avatar asked Jan 06 '14 09:01

Loko


1 Answers

This can also happen if your Oracle client DLL version number is mildly different from the reference you have in Visual Studio and even if you set that reference's "Specific Version" property to false.

like image 117
Alan Macdonald Avatar answered Sep 20 '22 12:09

Alan Macdonald