SydneyfunnelAllinOne
SydneyfunnelAllinOne

Reputation: 51

How can i connect access database on console application?

I want to update the database on my console application.

but here has an error:

The type name ‘OleDbConnection’ could not be found in the namespace ‘System.Data.OleDb’. 
This type has been forwarded to assembly ‘System.Data.OleDb, Version=4.0.1.0, 
Culture=neutral, PublicKeyToken=31bf3856ad364e35’ 
Consider adding a reference to that assembly.

I can easily reach datas from form application but when i try it on console application, i can not. there is my code:

using System;

using System.Data;

using System.Data.OleDb;


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            OleDbConnection baglanti = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=.\botbase.accdb");
        }

    }
}

there is the photo:

Error Image

Upvotes: 1

Views: 1989

Answers (2)

kapsiR
kapsiR

Reputation: 3177

I assume you are using .NET Core and not the .NET Framework?

So you probably have to use the .NET Platform Extensions (available as NuGet package):
System.Data.OleDb

The issue-comment that announces it:

Everyone,

Now that System.Data.OleDb is available on NuGet.org, it would be great if you could take it for a spin on .NET Core 3.0 preview 6. If you have an existing application, sample code, or a test that was blocked from working on .NET Core for lack of this functionality, please try now. We are hoping to get your help to cover a variety of OLEDB providers and scenarios, so we can identify any issues with the port before RTM.

Thanks!

Another really useful package for Windows dependent features:
Microsoft.Windows.Compatibility

Upvotes: 2

Patrick
Patrick

Reputation: 5846

OleDbConnection is in the System.Data.Common.DbConnection namespace.

Add a using clause to the top of your file for that namespace.

Upvotes: 1

Related Questions