0

I've been working on a C# Web Application for a while now, with the purpose of pulling values from a table and displaying them in a list box. However, once I run this program, it throws an exception at Line 37:

System.TypeInittalizationException: 'The type initializer for 
'Oracle.DataAccess.Client.OracleConnection' threw an exception.'
Inner Exception
OracleException: The provider is not compatible with the version of
Oracle Client

I've been searching for possible solutions across the internet, but they are all pretty outdated and I haven't been able to catch onto any fixes (I am relatively new and inexperienced with Oracle).

Here is the code. Any help would be appreciated.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Oracle.ManagedDataAccess;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

namespace Employee_Web_3
{
    public partial class FirstWebPage : System.Web.UI.Page
    {
        int MAX;
        List<string> save_vector = new List<string>();
        List<string> line_vector = new List<string>();
        List<string> singled_vector = new List<string>();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e) //Pull Values
        {
            MAX = int.Parse(Value_Count.Text);
            if (MAX <= 0)
            {
                Failure_Notice.Visible = true;
                Failure_Notice.Text = "Enter in a number greater than 0!";
            }
            else
            {
                string constr = "User Id=USER; Password=PASSWORD; Data Source=ORACLE DATABASE; enlist=false; pooling=false";
                OracleConnection conn = new OracleConnection(constr); //This is where the exception is being thrown
                conn.Open();

                OracleCommand cmd = new OracleCommand();
                cmd.Connection = conn;

                string line = MAX.ToString();

                cmd.CommandText = "select (employee_fname || ', ' || employee_lname || ' ' || employee_id) from Employee where employee_id <= " + line;
                cmd.CommandType = CommandType.Text;
                OracleDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    E_List.Items.Add(dr.GetString(0));
                }

                for (int i = 0; i < E_List.Items.Count; i++)
                {
                    save_vector.Add(E_List.Items[i].ToString());
                    line_vector.Add(E_List.Items[i].ToString());
                }

                conn.Dispose();

                E_List.Visible = true;
                Pull_Values.Visible = false;
                Value_Count.Visible = false;
                Failure_Notice.Visible = false;
                Prompt_.Visible = false;

            }
        }
    }
}

If anyone is able to give a solution, I would be very thankful

Paul_00
  • 11
  • 2

1 Answers1

0

You code has

using Oracle.ManagedDataAccess;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

The Oracle.ManagedDataAccess is different to Oracle.DataAccess, maybe this one helps: How to connect to Oracle 11 database from . net

Usually is does not make sense to use both of then, use only either of them

Looks like you installed several stuff. Check which DLL is actually loaded with:

conn.GetType().Assembly.Location
conn.GetType().Assembly.FullName

In case of Oracle.DataAccess compare it carefully with the version of your Oracle Client, the have to match exactly.

Have also a look at this one: The provider is not compatible with the version of Oracle client

Wernfried Domscheit
  • 38,841
  • 5
  • 50
  • 81