C# cannot find namespace OleDbConnection even though using System.Data.OleDb is there

Viewed 6578

I have one project (a web application), in production, where I have the following, which works, and then opened up another Visual Studio project (console application) and copy pasted the same code. The problem with the new project (console application) is that while the computer recognizes my namespace "System.Data.OleDb", VS is graying this out, and hovering over OleDbConnection gets the error message

The type or namespace name "OleDbConnection not found (are you missing a using directive or an assembly reference?)

Since my using directive is there, I'm guessing it's the assembly reference, but when I go to Project --> add reference the only options are Projects, Shared Projects, and Browse, and for each of these three tabs there are 0 options to choose from. How can I add this reference?

My simple code is below

using System.Data;
using System.Data.OleDb;
public class DataLayer
{
    public DataLayer()
    {
    }
    static OleDbConnection conn;
    // some other code below
}
3 Answers

In Visual Studio

  • Navigate to the Tools Tab
  • Click NuGet Packet Manager
    • Click Nuget Packet Manager Console // A command-line console should pop up at the bottom of Visual Studio
    • Insert the following command
    • Install-Package System.Data.OleDb

It should be good after that

You are missing the reference to System.Data, where this would be contained. Ideally you should ensure it is checked under References, but apparently you tried that.

enter image description here

You could always just edit the project file and add it manually, e.g.

enter image description here

The project needs a reference to System.Data.dll to be able to resolve. That dll can be located in the following directory (your use may vary based on framework, but pretty standard structure): C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2.

You should have an assmeblies section in your "Add Reference" window, but you can add by browsing to the location as well.

enter image description here

Related