private void btImport_Click(object sender, EventArgs e) { try { using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString)) { using (MySqlCommand cmd = new MySqlCommand()) { using (MySqlBackup mb = new MySqlBackup(cmd)) { cmd.Connection = conn; conn.Open(); mb.ImportFromString(textBox1.Text); conn.Close(); } } } MessageBox.Show("Import completed."); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private static bool ConfirmDBVersion() { try { string current_db_version=""; if(!connect()) return false; string query = "SELECT * FROM dbversion"; if(executeRead(query)) { if (data_reader.Read()) { current_db_version = data_reader["major"].ToString() + "." + data_reader["minor"].ToString() + "." + data_reader["patch"].ToString(); } else return false; } if (current_db_version==db_version) return true; else { BackUp(@"C:\Inventory\Old Database Backup", 10); Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(db_file_resource); if (stream == null) { ErrorHandler.Errors.displayError("We are unable to install database.", ErrorHandler.ErrorCode.DbFileMissing, ErrorHandler.ErrorAction.Exit, new Exception()); } StreamReader reader = new StreamReader(stream); string create_db_query = reader.ReadToEnd(); if (!connectWithoutDbName()) throw new Exception("Connecting to db failed"); MySqlBackup bk = new MySqlBackup(cmd); bk.ImportFromString(create_db_query); return true; } } catch (Exception ex) { dropDB(); ErrorHandler.Errors.displayError("We were unable to install database.", ErrorHandler.ErrorCode.ConfirmingDBExists, ErrorHandler.ErrorAction.Continue, ex); return false; } }
private static bool ConfirmDBExists() { try { if (DBExists()) return true; else { Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(db_file_resource); if(stream==null) { ErrorHandler.Errors.displayError("We are unable to install database.", ErrorHandler.ErrorCode.DbFileMissing, ErrorHandler.ErrorAction.Exit,new Exception()); } StreamReader reader = new StreamReader(stream); string create_db_query = reader.ReadToEnd(); if (!connectWithoutDbName()) throw new Exception("Connecting to db failed"); MySqlBackup bk = new MySqlBackup(cmd); bk.ImportFromString(create_db_query); return true; } } catch (Exception ex) { dropDB(); ErrorHandler.Errors.displayError("We were unable to install database.", ErrorHandler.ErrorCode.ConfirmingDBExists, ErrorHandler.ErrorAction.Continue, ex); return false; } }