0
votes

I am trying to connect database created in Oracle 11g. This is simple code I wanted to use to check connection in VS, but It doesn't even works:

    OleDbConnection conn = new OleDbConnection("Provider=MSDAORA; Data Source = localhost; User ID = library; Password = library; Unicode = True");
    private void button1_Click(object sender, EventArgs e)
    {
        conn.Open();
    }

I get this error when I click button:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: Error while trying to retrieve text for error ORA-01019

When I go to server explorer --> add connection and type in my database information, it works fine and connection shows up in server explorer.

I also get a warning in VS:

Severity Code Description Project File Line Suppression State Warning There was a mismatch between the processor architecture of the project being built "x86" and the processor architecture of the reference "Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. Biblioteka1

1
You should be using the managed oracle client. nuget.org/packages/Oracle.ManagedDataAccess. You should also check/search on the oracle error ORA-01019 in SO with c# or .net.Igor
What about this correct connection string => Provider=OraOLEDB.Oracle;Data Source=localhost;User Id=library; Password=library;CodeNotFound
@CodeNotFound, with this string I got error that provider OraOLEDB.Oracle is not registered on the local machine.ktos1234

1 Answers

2
votes

I'd really recommend you use Oracle's ODP.net. It works very efficiently between Oracle and .NET and can take advantage of many of the low level features (such as bulk inserts/updates) available through the Oracle Call Interface (OCI).

From there, ODP.net has a OracleConnectionStringBuilder class that demistifys the connection string difficulties you have with most databases:

OracleConnectionStringBuilder sb = new OracleConnectionStringBuilder();
sb.DataSource = "<your datasource>";
sb.UserID = "library";
sb.Password = "library";

OracleConnection conn = new OracleConnection(sb.ToString());
conn.Open();

If your database is remote, Oracle's EZ Connect makes it nice to not have to worry about TNS names:

sb.DataSource = "hostname.whatever.com:1521/ServiceName";