Dim con As New OleDb.OleDbConnection
Sub connecttodatabase(ByVal fileselected As String)
Dim databasepassword
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = " & fileselected
Try
con.Open()
Catch e As OleDb.OleDbException
If e.Message = "Not a valid password." Then
Console.WriteLine("Database has a password. Please enter password to continue.")
databasepassword = Console.ReadLine()
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = " & fileselected & ";JetOLEDB:Database Password=" & databasepassword & ";"
con.Open()
End If
errorid = 1
Finally
End Try
End Sub
我遇到的错误发生在第二个con.Open()当我尝试连接到我在访问时创建的.mdb数据库文件时,该函数正确地告诉我我有一个密码,但是一旦我输入了我的密码密码我得到标题中定义的错误,我不明白为什么。任何帮助将不胜感激。
答案 0 :(得分:1)
试试这个: Provider = Microsoft.Jet.OLEDB.4.0;数据源= C:\ mydatabase.mdb;用户ID = admin;密码= YOURPASS;
此外,您在第一次打开数据库时遇到了什么异常?也许是同样的问题:ISAM不存在。尝试重新安装MDAC:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=78cac895-efc2-4f8e-a9e0-3a1afbd5922e