4

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.

Adi Lester
  • 23,781
  • 12
  • 86
  • 106
jaredk
  • 898
  • 5
  • 23
  • 35

4 Answers4

4

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.

Nathan DeWitt
  • 6,321
  • 8
  • 42
  • 65
Adil
  • 3,156
  • 1
  • 20
  • 27
  • I have read about this solution, however it is not an option for me to use third-party software. – jaredk Aug 31 '12 at 17:48
  • 5
    If you have an Oracle database then using the Oracle client really isn't third party software – Jesse Aug 31 '12 at 17:55
1

I think the using directive got removed.

using System;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.OracleClient; //Add This
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;

Did you maybe try each of those steps individually and then set them back when they didn't work?

Zeph
  • 1,643
  • 17
  • 28
  • I have tried doing this as well, but then I get the error `CS0234: The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)` – jaredk Aug 31 '12 at 18:10
  • Expand the references folder in the solution explorer and make sure that the System.Data.OracleClient is still listed there – Zeph Aug 31 '12 at 18:12
  • Ok, Highlight the System.Data.OracleClient reference in the solutions explorer, then look in the properties window (if it's not there, go to view and choose "Properties Window") and please list the Runtime Version, Specific Version, Resolved, Path – Zeph Aug 31 '12 at 18:31
  • Runtime Version: v4.0.30319, Specific Version: False, Resolved: True, Path: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.OracleClient.dll – jaredk Aug 31 '12 at 18:36
  • Well that's about all I got. Does the syntax highlighter recognize the OracleConnection reference? i.e. is it highlighted (by default aqua). And does autocomplete recognize OracleClient if you type in "using System.Data." – Zeph Aug 31 '12 at 18:43
  • It does get recognized by the syntax highlighter (and it has a note attached saying that the method is deprecated). It is when I attempt to run the program that I get the compilation error. – jaredk Aug 31 '12 at 18:49
  • I'm out of things to try. I would create a new project of type console application, change the target fromework to .NET 4, add the reference to the OracleClient.dll and then create a simple main program that has the Using directive at the top and declares an oracleconnection in the body of the main and see if that works ok. – Zeph Aug 31 '12 at 19:00
  • I tried out your suggestion, and I was able to successfully create the connection. I have no idea what the problem was, but I am just going to start over and hope this doesn't come back up again. – jaredk Aug 31 '12 at 19:13
1

I managed to solve this one, though I don't know how what I changed affected anything. The DBHandler.cs file was located in a folder called "App_Code". Moving the file up one level (into the main project folder) seems to have solved the error.

jaredk
  • 898
  • 5
  • 23
  • 35
0

Project->Add reference->Oracle.DataAccess
Here there are two versions- 2.something and 4.something. When I selected the version 4 it did't resolve the namespace, but when I selected the version 2 it resolved!!

Sagar Kalburgi
  • 67
  • 1
  • 13