Link to home
Start Free TrialLog in
Avatar of David Hooley
David Hooley

asked on

Backing up an Access 97 database which has a password

Hi,

I've been given a vb.net program to take over from another developer, which uses an Access 97 database. The user has asked me to put a password on the database to stop it being opened up at free will.
The program runs a daily backup of the database using the  DAO Database engine. I'm not familiar with this, but at the moment, it cannot backup the database, as it keeps saying there's an invalid password.

Where do I put the password in this code, and how do I do it? (The error is on the dbo.CompactDatabase method)

 Private Sub asyncBackupDaily(ByVal state As Object)

        Try
            sql = "SELECT * FROM [System Settings]"
            dataAd = New OleDb.OleDbDataAdapter(sql, con)
            dataSet = New DataSet
            dataAd.Fill(dataSet)

            Dim currentDB As String = readIni("DATABASE", directorypath & "settings.ini")
            Dim newDB As String = dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & ".mdb"

            My.Computer.FileSystem.CopyFile(currentDB, dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & "-nc.mdb", True)

            If My.Computer.FileSystem.FileExists(newDB) = True Then
                My.Computer.FileSystem.DeleteFile(newDB)
            End If

            Dim dbo As New DAO.DBEngine
            dbo.CompactDatabase(dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & "-nc.mdb", newDB)

            Try
                My.Computer.FileSystem.DeleteFile(dataSet.Tables(0).Rows(0).Item("backupPath") & "backup" & DateTime.Now.ToString("yyyy-dd-MM") & "-nc.mdb")

            Catch ex As Exception
            End Try

            MsgBox("Daily auto-backup successful!", MsgBoxStyle.OkOnly, "Success")

        Catch ex As Exception
            errorLog(ex)

        End Try
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial