vb.net 在 VB2010 中打开受密码保护的 Access 2010 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25214602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open password-protected Access 2010 database in VB2010
提问by user3408339
I need to open a password-protected Access 2010 database from a VB2010 application. The connection works fine without a password, so I know I have all other parameters set correctly. But when I add the password to the connection string I get an error, "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done." I know the password is correct because it works when I copy and paste it into the password dialog when opening the database directly in Access.
我需要从 VB2010 应用程序打开受密码保护的 Access 2010 数据库。没有密码连接也能正常工作,所以我知道我已经正确设置了所有其他参数。但是当我将密码添加到连接字符串时,我收到一个错误,“多步 OLE DB 操作产生了错误。检查每个 OLE DB 状态值,如果可用。没有完成任何工作。” 我知道密码是正确的,因为它在我直接在 Access 中打开数据库时将其复制并粘贴到密码对话框中时有效。
Here is the code I use. The error occurs at the adapter.fill command:
这是我使用的代码。错误发生在adapter.fill 命令上:
Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + Application.StartupPath + "\MyData.accdb;Jet OLEDB:Database Password=MyPassword;")
Dim command As OleDbCommand = New OleDbCommand()
command.Connection = conn
command.CommandText = "SELECT * FROM MyTable"
Dim table As DataTable = New DataTable()
Dim adapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(command)
adapter.Fill(table)
回答by Jay S.
I think it's a bug in Access 2010 : https://www.connectionstrings.com/access-2010/
我认为这是 Access 2010 中的一个错误:https: //www.connectionstrings.com/access-2010/
Quote :
引用 :
With database password This is the connection string to use when you have an Access 2007 - 2013 database protected with a password using the "Set Database Password" function in Access.
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb; Jet OLEDB:Database Password=MyDbPassword;Some reports of problems with password longer than 14 characters. Also that some characters might cause trouble. If you are having problems, try change password to a short one with normal characters.
Note! Reports say that a database encrypted using Access 2010 - 2013 default encryption scheme does not work with this connection string. In Access; try options and choose 2007 encryption method instead. That should make it work. We do not know of any other solution. Please get in touch if other solutions is available!
使用数据库密码 这是当您使用 Access 中的“设置数据库密码”功能使用密码保护 Access 2007 - 2013 数据库时要使用的连接字符串。
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb; Jet OLEDB:Database Password=MyDbPassword;一些关于密码超过 14 个字符的问题的报告。此外,某些字符可能会引起麻烦。如果您遇到问题,请尝试将密码更改为具有正常字符的短密码。
笔记!报告称,使用 Access 2010 - 2013 默认加密方案加密的数据库不适用于此连接字符串。在访问中;尝试选项并选择 2007 加密方法。那应该使它起作用。我们不知道任何其他解决方案。如果有其他解决方案,请与我们联系!
Also, as a tip, you don't need to say
另外,作为提示,您无需说
Dim conn As OleDbConnection = New OleDbConnection("Connection String")
You can just do
你可以做
Dim conn As New OleDbConnection("Connection String)
回答by Rizwan
Worked on this problem for a while. All the clues are mentioned above, but had to incorporate them all together...
在这个问题上工作了一段时间。上面提到了所有的线索,但必须将它们全部合并在一起......
Under File - Options - Client Settings (scroll to the bottom)...
在文件 - 选项 - 客户端设置下(滚动到底部)...
Default Open Mode = Shared
默认打开模式 = 共享
Default record locking = No Locks
默认记录锁定 = 无锁定
Encryption Method = Use legacy
加密方法 = 使用旧版
Unencrypt and re-encrypt the database
解密并重新加密数据库
.Provider = "Microsoft.ACE.OLEDB.12.0;"
.ConnectionString = "Data Source=c:\dt\GenericDetail.accdb;Jet OLEDB:Database Password='ThePassword';"
.Open
参考:https: //social.msdn.microsoft.com/Forums/en-US/210e52e6-cae7-4312-a08a-20c3e50bc17d/ace-oledb120-excel-password-protected-access-trouble?forum=adodotnetdataproviders
回答by ZZ9
From:https://stackoverflow.com/posts/22485495/edit
来自:https: //stackoverflow.com/posts/22485495/edit
The method I used to do this is actually quite simple:
我用来做这个的方法其实很简单:
Set db = CurrentDb
Set dblink = DBEngine.OpenDatabase(strDbFile, False, False, ";PWD=" & strP)
For Each strTable In strLinkedTablesArray
DoCmd.TransferDatabase acLink, "Microsoft Access", dblink.name, acTable, _
strTable, strTable
Next
Hope that helps
希望有帮助

