Backing up Database in MySQL using C#

前端 未结 6 1225
有刺的猬
有刺的猬 2020-12-14 04:06

I created a Winforms in order to backup my Database. Then When I run my program it gives an Win32Exception was unhandled. \"The system cannot find the file specified\" Altho

6条回答
  •  [愿得一人]
    2020-12-14 04:54

    You may try this one.

        public void BackUpData(string file)
        {
            using (MySqlConnection con = new MySqlConnection { ConnectionString = config })
            {
                using (MySqlCommand cmd = new MySqlCommand { Connection = con })
                {
                    using (MySqlBackup mb = new MySqlBackup { Command = cmd })
                    {
    
    
                        try
                        {
                            con.Open();
    
                            try
                            {
                                mb.ExportToFile(file);
                            }
                            catch(MySqlException ex)
                            {
                                msgErr(ex.Message + " sql query error.");
                                return;
                            }
                        }
                        catch(MySqlException ex)
                        {
                            msgErr(ex.Message + " connection error.");
                            return;
                        }
    
    
    
                    }
    
                }
    
            }
    
        }
    

提交回复
热议问题