Click here to Skip to main content
14,384,743 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,

i'm trying to get backup to mysql database. I used this code

private void button1_Click(object sender, EventArgs e)
{
    string Coonstring = "datasource=localhost;port=3306;username=****;password=****;Charset=utf8";
    MySqlConnection cn= new MySqlConnection(Coonstring);
    MySqlCommand cmd;
    SaveFileDialog sf = new SaveFileDialog();
    sf.Filter = "Backup Files (*.Bak) |*.bak";
    if(sf.ShowDialog()==DialogResult.OK)
    {
        cmd = new MySqlCommand("Backup Database project To Disk='" + sf.FileName + "'", cn);
        cn.Open();
        cmd.ExecuteNonQuery();
        MessageBox.Show("Done");
        cn.Close();
    }
}


but i get error ( An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll

Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Backup Database project To Disk='C:\Users\tariq emad\Desktop\1\tt.bak'' at line 1).

So, any one can help me to fix this error?
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Mysql does not natively have backup command (like the MSSQL one in your code), read the following on how to backup : http://webcheatsheet.com/sql/mysql_backup_restore.php[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Dear Mehdi,

this is via shell or telnet.
I need it from C# button code

Regards
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100