Question

I need to restore the MySQL database that I used which is a service based database, when I click the button 'RESTORE DATABASE'. I'm using VB.Net 2010. I already did a research for any solution, but I can't come up with any idea how to make it work. Do you have any ideas in mind that might help? I'm currently doing how to backup the database, so any help would be really much appreciated.

Here is the sample code:

Private Sub cmdrestore_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdrestore.Click

    Dim s As System.IO.StreamWriter
    Try
        Dim portfolioPath As String = My.Application.Info.DirectoryPath
        FileCopy(portfolioPath & "\Backup\Database1.mdf", "C:\Payroll System\Database1.Mdf")
            MsgBox("Restore completed successfully", vbInformation, "DBBES-B Payroll System")

    Catch ex As Exception
        Dim MessageString As String = "Report this error to the system administrator: " & ControlChars.NewLine & ex.Message
        Dim TitleString As String = "Employee Master Details Data Load Failed"
        MessageBox.Show(MessageString, TitleString, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub
Was it helpful?

Solution

First you will want to create a batch file that successfully restores the database. There are plenty of examples when you search Google (MySQL database restore script).

Then your button will call your batch file using the Process class, like in the example found HERE. You will use a .bat of course not .exe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top