I am currently using a database within my program and I have no problem backing it up or restoring it when i am simply debugging. However if it is published and downloaded it cannot find the path that it needs to get to the database to copy it. My code is:

Public Sub backupDB()

        Dim portfolioPath As String = My.Application.Info.DirectoryPath

        FileCopy(portfolioPath & "\Information Sources\portfolioDB.mdb", "C:\Program Files\PortfolioGen2.0\DBBACKUP.mdb")

        MsgBox("Backup Successful")
    End Sub

    Public Sub restoreDB()

        Dim portfolioPath As String = My.Application.Info.DirectoryPath

        If MessageBox.Show("Restoring the database will erase any changes you have made since you last backup. Are you sure you want to do this?", _
                    "Confirm Delete", _
                    MessageBoxButtons.OKCancel, _
                    MessageBoxIcon.Question, _
                    MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.OK Then
            'Restore the database from a backup copy.
            FileCopy("C:\Program Files\PortfolioGen2.0\DBBACKUP.mdb", portfolioPath & "\Information Sources\portfolioDB.mdb")

            MsgBox("Database Restoration Successful")
        End If
8 Years
Discussion Span
Last Post by KillerOfDN

It could well be that My.Application.Info.DirectoryPath is not returning what you'd like after the application has been compiled. I know, for instance that the My.User.Name did'nt work with Windows Vista at one point.
Try something like Application.StartupPath & "\portfolioDB.mdb". Also, your application seems to be bound to the C:\ drive, consider using the My.Computer.FileSystem.SpecialDirectories.ProgramFiles property.

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.