1.第一步:下载 Microsoft Access Database Engine
Microsoft Access Database Engine 2010 Redistributable Download
2.第二步: 安装下载的引擎软件
3.第三步:重新连接;
代码如下:
private void button1_Click(object sender, EventArgs e) {
string dbFile = @"C:\Users\Administrator\Desktop\瀚光工作\实习工作\数据库原理\数据库应用系统\Student.accdb";
string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbFile;
OleDbConnection con = new OleDbConnection(constr);
try
{
con.Open();
MessageBox.Show("连接成功! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
con.Close();
MessageBox.Show("连接失败! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(ex.ToString());
}
}
参考链接:https://blog.csdn.net/cao919/article/details/123639612