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.