Hello everyone,
I am using WPF apps with MySQL database. I did create backup.sql file. Then, after create .exe file, how can I check if db exist then skip below code?
- private void Application_Startup(object sender, StartupEventArgs e)
- {
- RestoreBehavior();
- }
- private void RestoreBehavior()
- {
- string constring = "server=localhost;user=root;pwd=123456;";
- string file = @"C:\Program Files (x86)\xxxx\xxxx\backup.sql";
- using (MySqlConnection conn = new MySqlConnection(constring))
- {
- using (MySqlCommand cmd = new MySqlCommand())
- {
- using (MySqlBackup mb = new MySqlBackup(cmd))
- {
- cmd.Connection = conn;
- conn.Open();
- mb.ImportInfo.TargetDatabase = "mydb";/*Here,How can I check here if mydb exist then skip the code?*/
- mb.ImportInfo.DatabaseDefaultCharSet = "utf8";
- mb.ImportFromFile(file);
- }
- }
- }
- }