Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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

C#
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

Dear Mehdi,

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

Regards
 
Share this answer
 
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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900