Link to home
Start Free TrialLog in
Avatar of mlcktmguy
mlcktmguyFlag for United States of America

asked on

Change Jet DB Password from within VB

I have a VB 6.0 application that uses a MIcorsoft Jet Database 4.0 MDB as the data repository.  The MDB is password protected and I have the password buried in the VB code.  It is used whenever a connection string is created.

The problem:  The users have found out the password to the MDB.  This will allow them to enter the MDB whenever they want.  Although there I don't believe that there is malicious intent I am still worrried that with them being able to get into the MDB, all data integrity rules enforced by the VB code can be bypassed and integrity goes out the window.

The question:  Is there any way to change the password programatically from within my VB app?  I know that I could change it by recalling all of the existing MDB's, changing it manually and red-didistributing ther MDB but this is not practical, or possible.  I would prefer to have the next release of the product revise the DB password.  In fact this may be something that I would do periodically.

Can this be done?
Avatar of Computron
Computron

Avatar of mlcktmguy

ASKER

This is encouraging.  I may be reading or interpreting the example incorrectly but it looks like this is used to change a user password.  I need to change the password that protects the database.  The password that I am refering to is set as follows when in the MDB.

Tools
    Security
        Set Database Password

Once set, you must enter the password each time that you open the MDB.  This password is the same for all users.

I have the 'Microsoft ADO ext 2.8 for DDD and Security' included my project.  Based on your example I'm thinking that this might be possible for revision of the database password as well.  Any ideas on that one?
ASKER CERTIFIED SOLUTION
Avatar of leclairm
leclairm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could connect using this connection string:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Yourdb.mdb;Jet OLEDB:Database Password=CurrentPassword;"

Currentpassword can be stored in an ini or text file with your vb application and once you use the code above to change it, save the new password back to the file to be used next time it needs to be changed.


Thanks, I'm getting there but not quit there yet.  I am first trying to reset the password to blank using the code in the link that you provided.  The only change that I made was to use my connection instead of the one in the example.  Everything runs OK and I get the message 'Database Password has been reset.' but I still need the old password to open the database.

The code that I am using is:

Private Sub ResetDBPassword()
'
' resets the database password to blank/ no password
'
'   Dim cn As ADODB.Connection
   Dim sqlExecStr As String
   Dim ResetQuestion As Integer
   Dim connMode As Integer

'   Set cn = CurrentProject.Connection
   On Error Resume Next

' make sure DB is opened exclusive
    openConnExclusive connConnection
   If connConnection.Mode <> 12 Then
      MsgBox "Your database is not opened exclusively", vbCritical
      Exit Sub
   End If
   ResetQuestion = MsgBox("You have selected to reset the database" & _
            Chr(10) & Chr(13) & "to a blank password. Do you want to continue?", vbQuestion + vbYesNo, _
            "Reset Database Password")

    'Reset database password based on answer to message box.

    If ResetQuestion = 6 Then
        sqlExecStr = "ALTER DATABASE PASSWORD `` DBPassword"
'        CurrentProject.Connection.Execute sqlExecStr
        connConnection.Execute sqlExecStr
        MsgBox "Database Password has been reset."
    Else
        MsgBox "Database password has not been reset"
        Exit Sub
    End If

End Sub

I left the original code from the example but commented out the lines that I revised.  Any ideas?  It all appears to work but the password is still on the DB.
Anyone else?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, that worked