Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

c# - OLEDB connection to Access Database (accdb)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need the Access 2007 Runtime.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...