[英]Cannot access password protected Microsoft accdb database Microsoft.ACE.OLEDB.12.0
Windows 10 laptop x64 bit Windows 10笔记本电脑x64位
I have Microsoft Access 2010 我有Microsoft Access 2010
Drivers installed: 安装的驱动程序:
-Microsoft Office Access database engine 2007 (I think 32 bit) -Microsoft Office Access数据库引擎2007(我认为是32位)
-Microsoft Access database engine 2010 (I think 64 bit) -Microsoft Access数据库引擎2010(我认为是64位)
I recently inherited a C# project (I think .net 4.0) as a junior but I'm having trouble setting up the code properly and from what I've read it is due to the project using a (password protected) Microsoft Access Database. 我最近还是一个初学者,继承了一个C#项目(我认为是.net 4.0),但是我无法正确设置代码,而我读到的代码却是由于该项目使用了(受密码保护的)Microsoft Access Database。 Initially it was handled by one main developer before being handed to me. 最初,它是由一个主要开发人员处理的,然后才交给我。
Installing the 2007 Microsoft driver helped with "register issues", but I found that the program could not access the database. 安装2007 Microsoft驱动程序有助于解决“注册问题”,但是我发现该程序无法访问数据库。
Running the code I get an error below. 运行代码,我在下面收到一个错误。
System.Data.OleDb.OleDbException: Cannot open database ''. System.Data.OleDb.OleDbException:无法打开数据库“。 It may not be a database that your application recognizes, or the file may be corrupt. 它可能不是您的应用程序可以识别的数据库,或者文件可能已损坏。
I found that if I open Microsoft Access 2010, create an empty database, import everything from the original database, and then save without a password, then it appears to run fine. 我发现,如果打开Microsoft Access 2010,创建一个空数据库,从原始数据库中导入所有内容,然后在没有密码的情况下进行保存,则它似乎可以正常运行。 But when a password is involved, it stops working 但是,当涉及密码时,它将停止工作
My App.Config file: 我的App.Config文件:
<add key ="exampletest"
value ="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\test\testDB.accdb;" />
In my accesshelper file: 在我的accesshelper文件中:
Public static readonly string ConnectionString =
ConfigurationManager.AppSettings["exampletest"].ToString() +
"Jet OLEDB:Database Password=Abc1234;";
... ...
Using (OleDbConnection conn = new OleDbCommection(connectionString))
{
...
If (con.State !=ConnectionState.Open)
conn.Open();
...
}
The code works fine with the original developer, but I can't seem to reproduce the same success without workarounds like removing the password (the password on the code (Abc1234) is correct. I know because if I open the db in Microsoft Access 2010; I have to type the password) 该代码在原始开发人员中工作正常,但是如果没有变通办法,例如删除密码(代码(Abc1234)上的密码正确),我似乎无法获得相同的成功。我知道,如果我在Microsoft Access 2010中打开数据库;我必须输入密码)
Found the resolution The issue from what I've researched seems to be compatibility/conflict issues between 32bit/64bit Microsoft database drivers 找到解决方案我研究的问题似乎是32位/ 64位Microsoft数据库驱动程序之间的兼容性/冲突问题
(For reference, I have: Microsoft Access 2010 64 bit Microsoft Office Access Database engine 2007 (a 32bit driver) Microsoft Access database engine 2010 (a 64bit driver) ) (作为参考,我有:Microsoft Access 2010 64位Microsoft Office Access数据库引擎2007(32位驱动程序)Microsoft Access数据库引擎2010(64位驱动程序))
Driver-side, not sure I need both. 驱动程序端,不确定我是否需要两者。 But the 2007 driver was a MUST for me 但是2007年的司机对我来说是必须的
Now for the resolution: 现在解决:
In visual studio I just need to right click on the project and in the build section I just select "Any CPU" as the platform target (not the same as selecting Any CPU for debug/release 在Visual Studio中,我只需要右键单击该项目,然后在“构建”部分中,我只选择“任何CPU”作为平台目标(与选择“任何CPU进行调试/发布”不同)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.