0

I want to connect to an Oracle database from a .NET Web API application using OLE DB (if you think of something else that's simple, please feel free).

Connection string:

<add name="OraConnection" connectionString="Provider=MSDAORA.1;User ID=system;password=sa123;Data Source=127.0.0.1;Persist Security Info=False" />

C# code:

try
{
    string cnxString = ConfigurationManager.ConnectionStrings["OraConnection"].ConnectionString;
    string query = "SELECT COUNT(*) FROM TransferedCalls WHERE Agent = '@Agent';";
    using (OleDbConnection conn = new OleDbConnection(cnxString))
    {
        conn.Open();
        using (OleDbCommand comm = new OleDbCommand(q1))
        {
            comm.Connection = conn;
            comm.CommandType = System.Data.CommandType.Text;
            comm.Parameters.AddWithValue("@Agent", "login");
            try
            {
                int x = (Int32)comm.ExecuteScalar();
                if (x > 0)
                    return 1;
            }
            catch (SqlException x)
            {
                return 2;
            }
        }
    }
}
catch (Exception e)
{
    return 2;
}

I'm using a local Oracle XE 11g and I have Oracle instant client 11.0.2 installed.

The exception occurs at this statement conn.Open();:

The client components and Oracle network are not found. These components are supplied by Oracle Corporation in the customer installation of Oracle Version 7.3.3 (or later).

You can not use this provider before installing these components.

7
  • See stackoverflow.com/questions/9002560/… Commented May 23, 2016 at 15:09
  • I did installed the oracle client on my machine (32 and 64) but it's the same Commented May 23, 2016 at 15:29
  • What about the remote server? You might also try a connection string without tnsnames. connectionstrings.com/oracle-data-provider-for-net-odp-net/… Commented May 23, 2016 at 15:49
  • With that kind of connection strings, I get this exception message: ` An OLE DB provider was not specified in ConnectionString. For example, 'Provider = SQLOLEDB;'. ` Commented May 23, 2016 at 16:50
  • You have the providername attribute? stackoverflow.com/questions/16432576/… Commented May 23, 2016 at 17:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.