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.

Thanks!

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.")
        Else
            MsgBox("This program has detected no current database users and will proceed with database maintenance.")
        End If

        Try
            Directory.CreateDirectory(TempFolder)
        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.
        Try
            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")
        File.Delete(strAccessDatabasePath)

        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"

        

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

        Directory.Delete(TempFolder)

Nothing out there to help the newbie?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.