View Full Version : Password Protect ADO Database in VB6.0
gbrown
10-18-2004, 05:16 PM
I feel like such a dork (so what's new, eh?). I'm just fine opening an Access database with ADO using the "Jet OLEDB:Database Password=aardvark" kind of thing. All well and good for a database I protect using Access itself. I am at a loss as to how to change/remove the password programatically from within VB6. With DAO it was a piece of cake. I've tried all my usual sources on line, but to no avail. I know it's gonna be so simple I'm going to kick myself...
Thanks, all.
gbrown
10-18-2004, 05:53 PM
I just knew it.... as soon as I posted the note I found the solution. As guessed, pretty simple:
--------------------------------------------
Dim strSourceDB As String
Dim strDestDB As String
Dim JetEngine As JRO.JetEngine
Dim strSourceConnect As String
Dim strDestConnect As String
' Build connection strings for SourceConnection and
' DestConnection arguments.
strSourceDB = "original.mdb"
strSourceConnect = "Data Source=" & strSourceDB & ";Jet OLDEDB:Database Password=OldPassword"
strDestDB = "newdb.mdb"
strDestConnect = "Data Source=" & strDestDB & ";" & _
"Jet OLEDB:Encrypt Database=True;" & _
"Jet OLEDB:Database Password=NewPassword"
Set JetEngine = New JRO.JetEngine
' Compact and encrypt the database specified by strSourceDB
' to the name and path specified by strDestDB.
JetEngine.CompactDatabase strSourceConnect, strDestConnect
Set JetEngine = Nothing
---------------------------
*sigh*
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.