Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to an Oracle database

I'm trying to connect to an Oracle database but when the the code is executing the line:

con = new OracleConnection(oradb);

It gives this error. "The program can't start because oraons.dll is missing from your computer. Try reinstalling the program to fix this problem." I installed the ODP for .net on my computer already from the following site http://www.oracle.com/technetwork/topics/dotnet/index-085163.html and referenced the Oracle.DataAccess.

I also checked the folder that was installed and I can see the oraons dll in the folder. Here's the code:

class OracleDatabase
{
    OracleConnection con;
    public void ConnectToOracleDb()
    {
        string oradb = getConnectionString("host", 1521, "sid", "user", "pass");

        try
        {
            con = new OracleConnection(oradb);
            con.Open();
            Console.WriteLine("Connected to Oracle" + con.ServerVersion);
        }
        catch
        {
            Console.WriteLine("Could not connect to FLX");
        }

    }

    private static string getConnectionString(string databaseIP, int databasePort, string databaseSID, string databaseUN, string databasePW)
    {
        return string.Format(
            "Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1}))(CONNECT_DATA =(SID = {2})));" +
            "Persist Security Info=True;User ID={3};Password={4}",
            databaseIP, databasePort, databaseSID, databaseUN, databasePW
        );
    }
}

Why can't I connect any suggestions?

like image 717
kknaguib Avatar asked Feb 18 '14 19:02

kknaguib


People also ask

How do I connect to a database in Oracle?

To connect to Oracle Database from SQL*Plus: If you are on a Windows system, display a Windows command prompt. At the command prompt, type sqlplus and then press the key Enter. At the user name prompt, type your user name and then press the key Enter.

How do I connect an Oracle Database to another computer?

To connect to an Oracle database from a client computer using easy connect naming: Complete the steps in "Configuring the Operating System Environment Variables ". (Windows systems only) Click Start, select Programs (or All Programs), then Oracle - HOME_NAME, then Application Development, and then SQL*Plus.


3 Answers

I ended up referencing the ManagedDataAccess.Client instead of just the Data.Access.Client one and it worked.

like image 193
kknaguib Avatar answered Oct 17 '22 00:10

kknaguib


The PATH setting is not necessary. I solved the same issue with a copy of the oraons.dll into dhe ORACLE_HOME\bin folder and after that the installation works.

There is a difference between an Oracle setup via installer and the xcopy depoyment. I don't now why. Both installations had the same registry setting:

HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.112.4.0\DllPath 

and the DllPath points to the BIN folder of the ORACLE_HOME. That means a PATH setting to the BIN folder of the ORACLE_HOME does not help. An additional PATH to the ORACLE_HOME of the client would help. I think that is not necessary. Only a copy of the oraons.dll into the BIN is enough.

like image 21
Herbert Avatar answered Oct 17 '22 01:10

Herbert


I was getting that error in my test project. The problem was that I was opening Visual Studio from a command line that had an old PATH. After opening everything fresh, it worked.

Check the PATH from your code, and make sure the oracle folder is in the PATH.

like image 30
Carl Walsh Avatar answered Oct 17 '22 00:10

Carl Walsh