how to backup my sql database in vb.net

12,000

There is a complied DLL called MySqlBackup.NET. Actually it is an alternative to MySqlDump.

Features

  • Export/Import Table's Structures & Rows
  • Export/Import Stored Procedures, Functions, Triggers, Events, Views
  • Custom Tables and Rows Export.
  • Able to apply encryption to the process.
  • Export BLOB and save as files.
  • Gather SQL Syntax errors during Import process.
  • Export/Import will report progress. Enable the usage of progress bar.
  • Able to execute in Synchronous or Asynchronous mode.
  • Export/Import To/From Zip File.

For more info, see the link below,

Edited: Code Examples Added

Backup a MySql Database

Dim con As String = "server=localhost;user=root;pwd=1234;database=test;"
Dim file As String = "C:\backup.sql"
Dim mb As New MySqlBackup(con)
mb.ExportInfo.FileName = file
mb.Export()

Restore a MySql Database

Dim con As String = "server=localhost;user=root;pwd=1234;database=test;"
Dim file As String = "C:\backup.sql"
Dim mb As New MySqlBackup(con)
mb.ImportInfo.FileName = file
mb.Import()
Share:
12,000
Patrick Tutu
Author by

Patrick Tutu

Updated on June 04, 2022

Comments

  • Patrick Tutu
    Patrick Tutu almost 2 years

    i want the user of my vb application to be able to backup and restore the database (MySQL) onto a storage medium. my problem is that i dont want to specify 'c:\ in the code because i want the application to be able to locate the dumb file whether it is created on drive c or not. below is the code i used but when i installed it on another machine, it had its windows and program files on D:. it turns out that i have to check the drive letter of every machine, change it in the code before i publish the application to allow backup which i dont want to do that. i want it do be universal. thus whether the dump file is on driver C, G or whatever. any help. below is the code i used. Dim cmd As String

    Private Sub cmdBackup_Click()
        Screen.MousePointer = vbHourglass
        DoEvents
    
        cmd = Chr(34) & "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump" & Chr(34) & " -uroot -psecretpswd --routines --comments db_name > c:\MyBackup.sql"
        Call execCommand(cmd)
    
        Screen.MousePointer = vbDefault
        MsgBox "done"
    End Sub