10

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
}
12
  • 1
    I think you are missing an assembly reference as the error message implies. Go to your project and right click on References --> Add Reference --> select the OleDb assembly. Commented Nov 1, 2018 at 13:56
  • I've tried this, but there appear to be no options to choose from when I open this window. I've also typed in OleDb into the search bar with no results Commented Nov 1, 2018 at 13:58
  • If you don't have the data access engine installed. Then try Nuget package ADONetHelper.OleDb by Robert Garrisson Commented Nov 1, 2018 at 14:02
  • 3
    I'm laying strong odds on the bit you've forgotten to mention is that this new project is a .NET Core application (where the Ole classes aren't supported) rather than a .NET Framework one. Commented Nov 1, 2018 at 14:16
  • 1
    @kashmoney - Double click on the "Properties" list item that is under your project in the Solution Explorer....it will open a settings pages with multiple tabs...one of those is "Application" Commented Nov 1, 2018 at 14:20

3 Answers 3

19

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

OP has indicated that they have no Assemblies section in the Add Reference dialog. If that's the case, we need to get to the bottom of that before this advice could help. It would also be unusual since most project templates include a reference to System.Data by default anyway.
0

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

2 Comments

My project already has a reference to the System.Data.dll file
If that's the case, take a look at Damien's comment above about the Target Framework of the new application you copied this into. If the target framework of the app is not the same as the target framework that System.Data is (the one that is referenced), you will end up with this compile error.

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.