none
change access database password RRS feed

  • Question

  • hi

    i want to change  access database 2007 main file password by code


    • Edited by ahmeddc Saturday, March 23, 2019 1:28 PM
    Saturday, March 23, 2019 1:28 PM

Answers

  • Hello,

    Using your current connection string opened in exclusive mode as shown below where Database1.accdb is replaced with your database and 'Database Password' uses your current password for your database open the database.

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb;Jet OLEDB:Database Password=password;Mode=Share Exclusive

    Next using the OleDb Connection create a OleDb command with the following CommandText

    ALTER DATABASE PASSWORD newpassword currentpassword

    Where 'newpassword' is the new password to set for the database and 'currentpassword' is the current database password.

    Execute the command with cmd.ExecuteNonQuery where 'cmd' is your OleDbCommand.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by ahmeddc Saturday, March 23, 2019 6:42 PM
    Saturday, March 23, 2019 2:12 PM
    Moderator
  •  

    A way with DAO (add reference to Microsoft DAO 3.6 Object Library)

        Public Sub ChangePassword(ByVal sPath As String, ByVal sOldPassword As String, ByVal sNewPassword As String)
            Dim dbEngine As DAO.DBEngine = New DAO.DBEngine()
            Dim db As DAO.Database = dbEngine.OpenDatabase(sPath, True, False, ";PWD=" & sOldPassword)
            db.NewPassword(sOldPassword, sNewPassword)
            db.Close()
        End Sub




    • Edited by Castorix31 Saturday, March 23, 2019 2:13 PM
    • Marked as answer by ahmeddc Saturday, March 23, 2019 6:42 PM
    Saturday, March 23, 2019 2:13 PM

All replies

  • Hello,

    Using your current connection string opened in exclusive mode as shown below where Database1.accdb is replaced with your database and 'Database Password' uses your current password for your database open the database.

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb;Jet OLEDB:Database Password=password;Mode=Share Exclusive

    Next using the OleDb Connection create a OleDb command with the following CommandText

    ALTER DATABASE PASSWORD newpassword currentpassword

    Where 'newpassword' is the new password to set for the database and 'currentpassword' is the current database password.

    Execute the command with cmd.ExecuteNonQuery where 'cmd' is your OleDbCommand.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by ahmeddc Saturday, March 23, 2019 6:42 PM
    Saturday, March 23, 2019 2:12 PM
    Moderator
  •  

    A way with DAO (add reference to Microsoft DAO 3.6 Object Library)

        Public Sub ChangePassword(ByVal sPath As String, ByVal sOldPassword As String, ByVal sNewPassword As String)
            Dim dbEngine As DAO.DBEngine = New DAO.DBEngine()
            Dim db As DAO.Database = dbEngine.OpenDatabase(sPath, True, False, ";PWD=" & sOldPassword)
            db.NewPassword(sOldPassword, sNewPassword)
            db.Close()
        End Sub




    • Edited by Castorix31 Saturday, March 23, 2019 2:13 PM
    • Marked as answer by ahmeddc Saturday, March 23, 2019 6:42 PM
    Saturday, March 23, 2019 2:13 PM
  •  

    A way with DAO (add reference to Microsoft DAO 3.6 Object Library)

        Public Sub ChangePassword(ByVal sPath As String, ByVal sOldPassword As String, ByVal sNewPassword As String)
            Dim dbEngine As DAO.DBEngine = New DAO.DBEngine()
            Dim db As DAO.Database = dbEngine.OpenDatabase(sPath, True, False, ";PWD=" & sOldPassword)
            db.NewPassword(sOldPassword, sNewPassword)
            db.Close()
        End Sub




    This solution should be used with caution as on some Windows 10 machines this has been known to fail and may or may not resolve or if so not easily.

    Whenever possible avoid DAO methods in general.

      

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, March 23, 2019 2:24 PM
    Moderator
  • Hello,

    Using your current connection string opened in exclusive mode as shown below where Database1.accdb is replaced with your database and 'Database Password' uses your current password for your database open the database.

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb;Jet OLEDB:Database Password=password;Mode=Share Exclusive

    Next using the OleDb Connection create a OleDb command with the following CommandText

    ALTER DATABASE PASSWORD newpassword currentpassword

    Where 'newpassword' is the new password to set for the database and 'currentpassword' is the current database password.

    Execute the command with cmd.ExecuteNonQuery where 'cmd' is your OleDbCommand.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    error result

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim cons As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\database.accdb;Jet OLEDB:Database Password=224044444;Mode=Share Exclusive")
                Dim cmd As New OleDb.OleDbCommand("", cons)
                cmd.CommandText = "ALTER DATABASE PASSWORD 21304 224044444"
                cons.Open()
                cmd.ExecuteNonQuery()
                cons.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
           
        End Sub


    • Edited by ahmeddc Saturday, March 23, 2019 3:12 PM
    Saturday, March 23, 2019 3:11 PM
  • Hello,

    Using your current connection string opened in exclusive mode as shown below where Database1.accdb is replaced with your database and 'Database Password' uses your current password for your database open the database.

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb;Jet OLEDB:Database Password=password;Mode=Share Exclusive

    Next using the OleDb Connection create a OleDb command with the following CommandText

    ALTER DATABASE PASSWORD newpassword currentpassword

    Where 'newpassword' is the new password to set for the database and 'currentpassword' is the current database password.

    Execute the command with cmd.ExecuteNonQuery where 'cmd' is your OleDbCommand.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    thanks

    ALTER DATABASE PASSWORD [newpassword] [currentpassword]

    Saturday, March 23, 2019 6:42 PM