I want to make a simple application for an exercise, so it could be nice to connect to a simple database like Access (.accdb)
我想为一个练习创建一个简单的应用程序,这样连接到一个简单的数据库(如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:
我使用Visual Studio 2010。当我用“开始不调试”(CTRL+F5)来测试我的应用程序时,我得到了这个错误:
The 'Microsoft.ACE.OLEDB.14.0' provider is not registered on the local machine.
“microsoft.ac . oledb .14.0”提供程序没有在本地机器上注册。
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
我尝试从Microsoft omepage下载并安装“Microsoft Access Database Engine 2010 Redistributable”(64位):http://www.microsoft.com/download/en/details.aspx?
Unfortunately it sah not solved the problem. I still got the error when the myAdapptor.Fill() is executed. What is wrong?
不幸的是,它没有解决这个问题。当执行myadapptorr . fill()时,仍然会出现错误。是什么错了吗?
4 个解决方案
#2
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
对于其他对我的解决方案感兴趣的人,我发现microsoft . ac . oledb .14.0不支持Access 2010。相反,我使用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
您可以从这个站点下载他们的“2007办公系统驱动程序:数据连接组件”:2007办公系统驱动程序:数据连接组件
#3
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.
我也遇到过类似的问题,但只是计划旧的mdb。这样做的诀窍是,不需要下载任何额外的运行时。
#4
0
add using System.Data.OleDb
library.
使用System.Data添加。OleDb图书馆。
now for the connection string
现在是连接字符串
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Aishwar NIGAM\\Documents\\indianOil.accdb");
#1
#2
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
对于其他对我的解决方案感兴趣的人,我发现microsoft . ac . oledb .14.0不支持Access 2010。相反,我使用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
您可以从这个站点下载他们的“2007办公系统驱动程序:数据连接组件”:2007办公系统驱动程序:数据连接组件
#3
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.
我也遇到过类似的问题,但只是计划旧的mdb。这样做的诀窍是,不需要下载任何额外的运行时。
#4
0
add using System.Data.OleDb
library.
使用System.Data添加。OleDb图书馆。
now for the connection string
现在是连接字符串
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Aishwar NIGAM\\Documents\\indianOil.accdb");