问题描述
我遇到了很大的问题。使用Access 2010(* .accdb)和Excel 2010. 32位。从Excel连接到Access,一切都很好,但是当我将密码设置为Access文件时,我无法使连接正常工作。一直在网上搜索
,发现我不是唯一一个有这个...
I have a huge problem with following. Using Access 2010 (*.accdb) and Excel 2010. 32-bit. Connecting from Excel to Access and everything works great but when I set password to Access file then I cannot get the connection to work. Been searching the internet and found out that I'm not the only one with this...
这是一个不起作用的示例代码:
Here's a sample code which doesn't work:
Public Sub TestSub()
Dim strConnection As String
Dim cnn As ADODB.Connection
strConnection =" Provider = Microsoft.ACE.OLEDB.12.0;" &安培; _
"数据来源= C:\test.accdb;"&
设置cnn =新ADODB.Connection
cnn.ConnectionString = strConnection
cnn.Properties("Jet OLEDB:数据库密码")=" test"
cnn.Open
Debug.Print cnn.State = adStateOpen
cnn.Close
结束子
Public Sub TestSub()
Dim strConnection As String
Dim cnn As ADODB.Connection
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\test.accdb;"
Set cnn = New ADODB.Connection
cnn.ConnectionString = strConnection
cnn.Properties("Jet OLEDB:Database Password") = "test"
cnn.Open
Debug.Print cnn.State = adStateOpen
cnn.Close
End Sub
如果Access文件没有密码保护,一切正常但是当它出现时,总是"没有有效的密码"。错误。我100%确定密码是否正确。我也知道,当使用Windows 7,Access 2010,Excel 2010时,代码适用于Windows XP(Access 2007,Excel 2007)计算机,但不适用于
。这是一个错误还是什么错?我有什么选择,因为这个文件需要密码?
Everything works if the Access file is not password protected but when it is, there's always "not a valid password" error. I'm 100% sure that password is correct. I know also that the code works with Windows XP (Access 2007, Excel 2007) computer but not when Windows 7, Access 2010, Excel 2010 are used. Is this a bug or what's wrong? And what options do I have because password is needed for this file?
推荐答案
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\...\Documents\My Database\Access\NorthwindPassword.accdb;Jet OLEDB:Database Password='password';Mode=Share Exclusive"
BTW,Windows 7中的root用户受UAC保护,因此您很可能在该位置打开数据库时遇到问题。
BTW, the root in Windows 7 is protected by UAC so you will very likely have problems opening the database at that location.
这篇关于Ace OLEDB.12.0 Excel< - > (密码保护)访问麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!