PDA

Click to See Complete Forum and Search --> : using ADO with password protected MS ACCESS97


rod
Jun 8th, 2000, 10:27 AM
hi! how can u connect ADO with a password protected MS ACCESS97 . i've been using DAO 3.51 with the following code:


Dim MyWS as Workspace
Dim MyDB as Database
Dim MyTable as Recordset

Set MyWS=DBEngine.Workspaces(0)

'*** Here's how to open a database with password ***
Set MyDB=MyWS.OpenDatabase("C:\MyMDB.MDB",False,False, _
"MS ACCESS;PWD=MyPassword")


this code works without a problem. but when i use ADO with the following code:


strconn = "Provider=Microsoft.Jet.OLEDB.3.51;Data" & _
"Source=C:\MyMDB.MDB;" & _
"User ID=Admin;Password=MyPassword;"
Set cnMyCon = New ADODB.Connection
cnMyCon.Open strconn


it gave me this error:

Run-Time Error '-2147467259(80004005)
Can't start your application. The workgroup information file is missing or opened exclusively by another user.


there's no one accessing the MyMDB database, therefore it's not exclusively opened and i'm not using any workgroup information file (system.mdw) in my previous codes (using DAO 3.51).

what am i missing. i'll appreciate any help

thanks

rod

Mongo
Jun 8th, 2000, 11:33 AM
This may help.

Function GetJetConnection(strPath As String, lngMode As ADODB.ConnectModeEnum, _
Optional strDBPwd As String, Optional strSysDBPath As String, _
Optional strUserID As String, Optional strUserPwd As String _
Optional lngEngineType As opgJetEngineType) As ADODB.Connection
Dim cnnDB As ADODB.Connection
Set cnnDB = New ADODB.Connection
With cnnDB
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Mode = lngMode
.Properties("Jet OLEDB:Database Password") = strDBPwd
.Properties("Jet OLEDDB:System Database") = strSysDBPwd
.Properties("Jet OLEDDB:Engine Type") = lngEngineType
.Open ConnectionString:=strPath, UserID:=strUserID, Password:=strUserPwd
End With
Set GetJetConnection = cnnDB
End Function