The type or namespace name 'OracleConnection' could not be found

jaredk picture jaredk · Aug 31, 2012 · Viewed 22.3k times · Source

I am getting this error every time I try to debug my program:

CS0246: The type or namespace name 'OracleConnection' could not be found (are you missing a using directive or an assembly reference?)

This occurs on the declaration private readonly OracleConnection oracleConnection; (and in a few other places as well)

I have been trying a number of suggested solutions but so far none have worked:

  • I have added a reference to the System.Data.OracleClient.dll
  • My target framework is set to .NET Framework 4
  • I have tried both including using System.Data.OracleClient and manually writing out System.Data.OracleClient.OracleConnection

EDIT: The code I am using is as follows:

using System;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Foo
{
    public class DBHandler
    {
        private readonly OracleConnection oracleConnection;
        private readonly OracleCommand oracleCommand;
        private readonly OracleDataAdapter oracleAdapter;

Nothing has worked so far, so any suggestions would be appreciated.

Answer

Adil picture Adil · Aug 31, 2012

First of all, for Oracle, System.Data.OracleClient has been deprecated and therefore it's not been recommended now. For details, please visit ADO.NET Team Blog Post

What is recommended is Oracle client published by Oracle corporation. Download the Oracle Data Access component from Oracle .NET Developer Center

Then in the same way, you can use OracleConnection, OracleCommand etc. by adding reference to Oracle.Client dll.

Further please note this library wont be available for .NET 4 Client Profile.