First time poster here...

My VB.NET program compacts and repairs my DB, but somewhere in the process unsets the database password. No problem, just reset it through VB, right? Ummm... not sure how to go about that task.

So I either need to know how to compact it without losing the password, or how to reset the password after I lose it.


Dim strAccessDatabasePath As String = System.AppDomain.CurrentDomain.BaseDirectory & "App_Data\Squirrel.accdb"
        Dim LockedDbFileInfo As New System.IO.FileInfo(strAccessDatabasePath.Replace(".accdb", ".laccdb"))
        Dim TempFolder As String = System.AppDomain.CurrentDomain.BaseDirectory & "App_Data\temp"
        Dim TempDB As String = TempFolder & "\temp.accdb"

        If LockedDbFileInfo.Exists Then
            MsgBox("Database is in use. Please make sure no users are in the database before performing maintenance.")
            MsgBox("This program has detected no current database users and will proceed with database maintenance.")
        End If

        Catch ex As Exception
            MsgBox("There has been an error creating a temporary directory in your application directory. Please check credentials and try again.")
        End Try

        Dim time As DateTime = DateTime.Now
        Dim format As String = "MMM d yyyy HHmmss "
        Dim TempDateTime As String = time.ToString(format)

        'Copy DB to backup directory.
            File.Copy(strAccessDatabasePath, txtDBbackupFolder.Text & "\" & "DBbkup " & TempDateTime & ".accdb")
        Catch ex As Exception
            MsgBox("There was an issue writing to the backup folder. Please check credentials and try again.")
        End Try

        'Copy DB to temp directory for maintenance.
        File.Copy(strAccessDatabasePath, TempFolder & "\" & "temp.accdb")

        Dim JROEng As Object

        JROEng = CreateObject("JRO.JetEngine")

        JROEng.CompactDatabase("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & TempDB & ";Jet OLEDB:Database Password=woodkitten70;Jet OLEDB:Engine Type=5", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
                               strAccessDatabasePath & ";Jet OLEDB:Engine Type=5")

        'connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\App_Data\Squirrel.accdb;Jet OLEDB:Database Password=woodkitten70"


            Kill(TempFolder & "\*.*")
        Catch ex As Exception
        End Try

This article has been dead for over six months. Start a new discussion instead.