14

I want to make a simple application for an exercise, so it could be nice to connect to a simple database like Access (.accdb)

My program looks like this:

using System;
using System.Collections.Generic; 
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;

namespace myProject.Account
{
    public class DbManager
    {
       private OleDbConnection _dbConnection;

       public void OpenDbConnection()
       {
        _dbConnection = new OleDbConnection {ConnectionString = GetConnectionString()};
       }

       private string GetConnectionString()
       {
        return "Provider=Microsoft.ACE.OLEDB.14.0;Data Source=exercise1.accdb";
       }

       public void CloseDbConnection()
       {
        _dbConnection.Close();
       }

       public void GetUser()
       {
        DataSet myDataSet = new DataSet();
        var myAdapptor = new OleDbDataAdapter();
        OleDbCommand command = new OleDbCommand("SELECT * FROM tblUser", _dbConnection);
        myAdapptor.SelectCommand = command;
        myAdapptor.Fill(myDataSet, "tblUser");
       } 

    }
  }

I using Visual Studio 2010. When I test my application by using the built in debug mode "Start without Debugging" (CTRL+F5) I get this error:

The 'Microsoft.ACE.OLEDB.14.0' provider is not registered on the local machine.

I have tried to download and install "Microsoft Access Database Engine 2010 Redistributable" (64 bit) from Microsoft omepage: http://www.microsoft.com/download/en/details.aspx?id=13255

Unfortunately it sah not solved the problem. I still got the error when the myAdapptor.Fill() is executed. What is wrong?

oberfreak
  • 1,799
  • 13
  • 20
Jedi
  • 397
  • 2
  • 4
  • 11
  • what is the bitness of your operating system? If the OS is 32 bit, 64 bit won't work and vica-versa and you they don't install side by side. – MatthewMartin Nov 28 '11 at 21:45

4 Answers4

6

You need the Access 2007 Runtime.

Tom Bass
  • 362
  • 4
  • 12
  • Thanks for the answer. Your solution might also help. I figured it out by downloading the "2007 Office System Driver" from this site: http://www.microsoft.com/download/en/confirmation.aspx?displayLang=en&id=23734 I thing the "Access 2007 Runtime" you suggest will do the same job :-) . – Jedi Nov 30 '11 at 09:23
  • 2
    Access 2007 Runtime provides Microsoft.ACE.OLEDB.12.0 If you want to use 14th you have to download Access 2010 Runtime http://www.microsoft.com/en-us/download/details.aspx?id=10910 – Anton Sivov Nov 13 '13 at 08:44
2

add using System.Data.OleDb library.

now for the connection string

OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Aishwar NIGAM\\Documents\\indianOil.accdb");
Rajesh
  • 10,318
  • 16
  • 44
  • 64
2

For others that are interested in my solution, I figured out that Microsoft.ACE.OLEDB.14.0 is not supported for Access 2010. Instead I used Microsoft.ACE.OLEDB.12.0

You can download their "2007 Office System Driver: Data Connectivity Components" from this site: 2007 Office System Driver: Data Connectivity Components

Justin
  • 84,773
  • 49
  • 224
  • 367
Jedi
  • 397
  • 2
  • 4
  • 11
0

Had a similar problem but just a plan old mdb in my case. Provider=Microsoft.Jet.OLEDB.4.0 does the trick for that, no need to download any extra runtimes.

Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87