How to Change the Database Password Programmatically?

Submitted by: 
Visitors have accessed this post 25124 times.

This tutorial will teach you on how to change the database password of an Access database programmatically using visual basic 6.0.

CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabasePath & ";Persist Security Info=False;Mode=12;Jet OLEDB:Database Password="current password here"
  1. sqlExecStr = "ALTER Database Password " & txtNewPass & " " & txtOldPass & ";"
  2.  
  3. CN.Execute sqlExecStr

Where CN is your database connection variable.

If you use the database before changing the password be sure to close it by adding code like:

CN.close

Open the database exclusively by adding:

Mode=12;

This is very important since you cannot change the password if you did not open it exclusively.


Comments

hi i tried the code mentioned at topmost however i get the error "method execute of object objConnection failed however i confirm the file is open with mode=12 what could be the reason

I am vb programmer

Hi Everyone,
Can I know how to use combo box when I click the first combo box , the second combox also change to display data related to first combo box?

I'm just start to learn vb6 and i'm new in this language. Can anyone help me please..
Thank you very much..

My code is as follows,

------------------
Set con = New ADODB.Connection

Dim strConstring As String, strChgPw
Dim newPassword As String
Dim oldpassword As String

newPassword = "Sid"
oldpassword = "Null"

strConstring = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MGallary;Data Source=SIDDHESH-DFF718"

con.Open strConstring

strChgPw = "ALTER Database Password " & newPassword & " " & oldpassword & ";"
con.Execute strChgPw
---------------------------------

But while running it promts error for line
con.Execute strChgPw

as: Incorrect syntax error near keyword 'Null'

I have not set any password for my database
Please help

also close the connection after
con.Execute strChgPw
write here con.close

is there more understandable code for changing password using vb 6.0??:) thanks

Hi there!
I would like to change my password that is stored on the database?

hi i declared my obeject as folloes but it complains.here is the code
Dim objUser As User

If txtUsername.Text <> "" Then
If txtNewPassword.Text = txtConfirmNew.Text Then
objUser = GetObject("LDAP://cn=" + txtUsername.Text _
+ ",cn=Users,dc=mycorp,dc=com")

objUser.SetPassword(txtNewPassword.Text)
objUser.pwdLastSet = 0
objUser.lockoutTime = 0
objUser.SetInfo()

'Reset everything
txtUsername.Text = ""
txtNewPassword.Text = ""
txtConfirmNew.Text = ""

MsgBox("Password changed!")
Else
MsgBox("Passwords are not the same, please try again!")
End If
Else
MsgBox("A username must be specified!")
End If

What is the error you encounter?

  1. Option Explicit
  2.  
  3. Public ADOCON As ADODB.Connection
  4. Public ADORECORD As ADODB.Recordset
  5.  
  6. Public Sub ConnectToDB(ByVal dbPath As String, Optional ByVal Password As String = "")
  7. Dim conStr As String
  8.  
  9.  
  10. conStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath & ";Jet OLEDB:Database Password=" & Password & ";"
  11.  
  12. ADOCON.CursorLocation = adUseClient
  13. ADOCON.Mode = adModeReadWrite
  14. ADOCON.Open conStr
  15.  
  16. End Sub
  17.  
  18. Public Function ChangeDatabasePassword(dbPath As String, oldPassword As String, newPassword As String) As Boolean
  19. Dim sqlStr As String, conStr As String
  20.  
  21.  
  22. conStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath & ";Jet OLEDB:Database Password=" & oldPassword & ";"
  23.  
  24. If ADOCON.State <> 0 Then ADOCON.Close
  25.  
  26. sqlStr = "ALTER Database Password " & newPassword & " " & oldPassword & ";"
  27. ADOCON.Mode = adModeShareExclusive
  28. ADOCON.Open conStr
  29. ADOCON.Execute sqlStr
  30. ADOCON.Close
  31. Call mADO.ConnectToDB(App.Path & "\dbpw.mdb", newPassword)
  32.  
  33. End Function

Thats How i got it to work :D

HOW CAN ME WRITE IT IN VISUAL BASIC 2008

AND HOW CAN ME CREATE NEW PASSWORD FOR ACCESS 2003

how did you initialized the CN variable? please send me the answer here [email protected]

Public CN As New Connection

I am a regular beneficiary of your tips and helps, keep up the good job. I must tell you, am inpressed by your selfless devotion to helping developers.

what is the databse password .

my id is [email protected]

Search for term "password" in the code editor window. Be sure to select current project.

how do i get the password to the downloaded VOTING SYSTEM software?

 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.