Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing an MS Access Password Protected database from within VB Code

Status
Not open for further replies.

tpbjr

MIS
Oct 8, 2004
120
US
Hi everyone,

I am trying to allow my application to change it's MS Access database password. I have to have the database password protected but I also need the user to be able to change that password from with my VB application that I am creating.

Thanks in advance.

Thank you for all your help

Tom
 

Open an exclusive connection (myCnn) to your db and run this code

myCnn.Execute "ALTER DATABASE PASSWORD " & myNewPassword & " " & myOldPassword

Setting password for the first time use OldPassword->NULL
Removing it NewPassword-->NULL

 
I have not tried this yet because I am not at my programming computer, but how do I open an exclusive connection via code? I know how to do that from the MS Access GUI.

Thank you for all your help

Tom
 
Declare a connection object, open it using a connection string, then use the object's execute function to execute sql statements. Since you want to have the database password protected, however, you should know that the Access password protection is not really considered protection since the password entry can be avoided by holding down some button I can't recall at the moment. Do a search in tek-tips, there should be numerous discussions on the topic.
-Max
 
Holding down the shift key by-passes certain features but to the best of my knowledge it does not by-pass the password protection. I do know that there are programs that can decode the password but I will be encrypting the data before I store it to the fields so even if someone breaks the password they will be left with decoding the data.

Check my website out I have developed a program called Access Lock that handles what I believe you were talking about.

Thanks to everyone for all your help, GOD knows I need it:)

Thank you for all your help

Tom
 
I just tried executing...
cnn.Execute "ALTER DATABASE PASSWORD " & "123" & " " & "abc"

And received the following message...
Cannot change password on a shared open database.

That is why I am asking how to open a database via code in Exclusive mode.

I know from the Access Database GUI you have to open the database in exclusive mode only before you are allowed to change the password. I just need to know how to do that via code.

Thanks


Thank you for all your help

Tom
 
Ok I figured out what I needed.

Here is exactly what works. Noticed the 'MODE=' portion. After I put that in it worked

con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\VbProjects\Myexes\Secret_Revised\Secrets.mdb;Mode=Share Deny Read|Share Deny Write;Persist Security Info=False;Jet OLEDB:Database Password=old_password"
cnn.Execute "ALTER DATABASE PASSWORD " & "new_password" & " " & "old_password"



Everyone--thanks again.

Thank you for all your help

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top