Also, an apparent bug in the 16-bit Jet 2.5 database engine causes the DBEngine’s CreateWorkspace method to fail unless the DefaultUser and DefaultPassword properties contain the values required by the secured database. And so, for your coding pleasure, I’m is pleased to present the following examples:
For 16-bit programs, you must first create an APPNAME.INI file (where APPNAME is the base name of your program’s .EXE file) containing at least the following:
[Data]
Database=D:\PATH\DBNAME.MDB
[Options]
SystemDB=D:\PATH\SYSTEM.MDA
Then, to open the database, do this:
Dim sUserName As String
Dim sPassword As String
Dim db As Database
Dim ws As Workspace
sUserName = "Your Name Here"
sPassword = "Bite_Me"
' Create secured workspace
With DBEngine
.IniPath = "D:\PATH\APPNAME.INI"
.DefaultUser = sUserName
.DefaultPassword = sPassword
End With
' Workspace name is arbitrary,
' but must be unique
Set ws = DBEngine.CreateWorkspace("Name", sUserName, sPassword)
' Open database via secured workspace
Set db = ws.OpenDatabase("D:\PATH\DBNAME.MDB"...)
32-bit programs do not require an .INI file, nor do they require you to set the DefaultUser and DefaultPassword properties. Simply set the DBEngine’s SystemDB property to point to your system database:
Dim sUserName As String
Dim sPassword As String
Dim db As Database
Dim ws As Workspace
sUserName = "Your Name Here"
sPassword = "Bite_Me"
' Create secured workspace
DBEngine.SystemDB = "D:\PATH\SYSTEM.MDW"
Set ws = DBEngine.CreateWorkspace("Name", sUserName, sPassword)
' That's it! Open sesame...
Set db = ws.OpenDatabase("D:\PATH\DBNAME.MDB"...)
Note: These examples assume that you have properly secured the database using the Access Security Wizard. During that process, Access will create the SYSTEM.MDA or .MDW files mentioned above.
Tip Submitted By: Phil Weber
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
