0

Since monday I followed several tutorials to establish connection to my Oracle database.

I downloaded at http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html and launched "install.bat".

In visual studio, in reference section I browsed the directory that I downloaded and found "Oracle.DataAccess.dll" in the following path "\odp.net4\odp.net\bin\4".

When I run my code I get the following error:

External component has thrown an exception

Furthermore I have the following warning :

Warning 1 There is a difference between the project processor architecture being generated "MSIL" and the reference processor architecture "Oracle.DataAccess, Version = 4.121.2.0, Culture = neutral, PublicKeyToken = 89b483f429c47342, processorArchitecture = x86 "," AMD64 ". This difference can lead to runtime problems.

I don't understand this error so I hope you will be able to help me.

Or if you know a better way to connect to a database oracle, I will be interested.

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        OraTest oraTest = new OraTest();
        oraTest.Connect();
        oraTest.Close();
        MessageBox.Show("Connecté");
    }
}
}

using Oracle.DataAccess.Client;

namespace WindowsFormsApplication2
{
class OraTest
{
    OracleConnection con;
    public void Connect()
    {
        con = new OracleConnection();
        con.ConnectionString = "User Id=<username>;Password=<password>;Data Source=<datasource>";
        con.Open();
        Console.WriteLine("Connected to Oracle" + con.ServerVersion);
    }

    public void Close()
    {
        con.Close();
        con.Dispose();
    }
}
}
Majestic
  • 757
  • 2
  • 10
  • 29
Millet Antoine
  • 313
  • 4
  • 19
  • The error basically means that the oracle dll's are 32 bit but parts of your project are either 'Any CPU' or 64 bit. – Paul Zahra May 31 '16 at 08:24
  • Possible duplicate of [Connecting to Oracle Database through C#?](http://stackoverflow.com/questions/12568100/connecting-to-oracle-database-through-c) – kayess May 31 '16 at 08:24
  • While adding reference where did you browse? You should find Oracle.Data.Access in reference listing. Also location should be something in here `c:\App\` - where you installed ODAC. – Renatas M. May 31 '16 at 08:24
  • Tip: backup your project before changing the bitness... http://stackoverflow.com/questions/10113532/how-do-i-fix-the-visual-studio-compile-error-mismatch-between-processor-archit – Paul Zahra May 31 '16 at 08:26
  • Final tip: make sure your connection string it correct... https://www.connectionstrings.com/oracle/ – Paul Zahra May 31 '16 at 08:28
  • From http://forums.asp.net/t/1961351.aspx?VS+2013+Compile+error+There+was+a+mismatch+between+the+processor+architecture+of+the+project ... It seems you are referencing AMD64 assemblies from MSIL assemblies. This is not likely not allowed as there is no point in having MSIL assemblies referencing a processor specific assembly. Where have you searched for those assemblies and added them to your project ? Have you done something like adding a reference to native generated assemblies ? – Paul Zahra May 31 '16 at 08:30
  • One last point... it is not an error... it is a warning... you have visual studio set to exit build on warnings – Paul Zahra May 31 '16 at 08:31
  • I have downloaded 64 bit version , I found the "oracle.dataAccess.dll" in the file that I downloaded because I didn't find in the list. I'm pretty sure it is not related to the connection string. I know it's only a warning but i think it's very very importanted to treat him for resolve my problem – Millet Antoine May 31 '16 at 08:37
  • 1
    You could try resolving by setting your project to be the same as the dll... i.e. from the information you have given it looks as though the oracle dll is set to run in 32 bit mode on an AMD64 processor... you can either set your project to run as the same... or look for a non-processor specific oracle dll. – Paul Zahra May 31 '16 at 08:49
  • From my experience with oracle, one thing I know - you should never add reference from other than installation path or gac, when you dealing with oracle. You'll get errors sooner or later if you add reference to stand-alone assembly. You probably getting error because of native oracle components missing or having internal exceptions. Try to find any step by step tutorial how to set up oracle. For example [this one](https://docs.oracle.com/cd/E11882_01/appdev.112/e10767/installation.htm#TDPNG20020) – Renatas M. May 31 '16 at 10:22
  • Have a look at this answer: http://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-client#25412992 – Wernfried Domscheit May 31 '16 at 17:34

1 Answers1

0

I suggest to use Official Oracle ODP.NET

In Nuget type:

Install-Package Oracle.ManagedDataAccess

MSL
  • 839
  • 1
  • 13
  • 24