private void btExport_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox1.Refresh();
            this.Refresh();
            try
            {
                using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();

                            textBox1.Text = mb.ExportToString();

                            conn.Close();
                        }
                    }
                }
                MessageBox.Show("Export completed.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        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);
            }
        }
Пример #3
0
        private void btExport_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
                return;

            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.ExportToFile(Program.TargetFile);

                            conn.Close();
                        }
                    }
                }

                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #4
0
        protected void btExport_Click(object sender, EventArgs e)
        {
            try
            {
                string output = "";

                using (MySqlConnection conn = new MySqlConnection(txtConnString.Text))
                {
                    MySqlCommand cmd = new MySqlCommand();
                    MySqlBackup mb = new MySqlBackup(cmd);
                    cmd.Connection = conn;
                    conn.Open();

                    output = mb.ExportToString();
                }

                if (output.Length > (1024 * 100))
                {
                    lbError.Text = "The length of the output file has exceeded 100KB maximum length limit.<br />Try to use a smaller size of MySQL database sample.";
                    lbError.Visible = true;
                }
                else
                {
                    StoreFile.StoreSqlText(output);
                    Server.Transfer("~/Result.aspx", true);
                }
            }
            catch (Exception ex)
            {
                lbError.Text = ex.Message;
                lbError.Visible = true;
            }
        }
        private void btExportWithNewHeadersFooters_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
                return;

            try
            {
                using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();

                            List<string> lstHeaders = new List<string>(txtHeaders.Lines);
                            List<string> lstFooters = new List<string>(txtFooters.Lines);

                            mb.ExportInfo.SetDocumentHeaders(lstHeaders);
                            mb.ExportInfo.SetDocumentFooters(lstFooters);

                            mb.ExportToFile(Program.TargetFile);
                        }
                    }
                }
                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #6
0
 //Backup
 public void Backup()
 {
     try
     {
         string constring = "server=localhost;user=quizuser;pwd=quizpassword;database=quizappmysql;";
         string file = "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.ExportToFile(file);
                     conn.Close();
                 }
             }
         }
     }
     catch (System.IO.IOException ex)
     {
         System.Windows.Forms.MessageBox.Show("Error , unable to backup!");
     }
 }
Пример #7
0
        public static void importBackUp(String filename)
        {
            try
            {

                var connection = System.Configuration.ConfigurationManager.ConnectionStrings["admEntities"].ConnectionString;//.Replace("&quot;", "'");
                string constring = connection.Remove(0, connection.IndexOf("server=")).Replace("\"", "");// "server=localhost;user id=root;port=3300;database=adm";// connection;
                string file = filename;
                using (MySqlConnection conn = new MySqlConnection(constring))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            mb.ImportFromFile(file);
                            conn.Close();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log.write(e.Message + " " + e.InnerException?.Message);
                throw e;

            }
        }
        private void btImport_Click(object sender, EventArgs e)
        {
            try
            {
                if (_ba == null || _ba.Length == 0)
                {
                    MessageBox.Show("No content is loaded into memory, cannot perform Import/Restore task.");
                    return;
                }

                MemoryStream ms = new MemoryStream(_ba);
                MySqlConnection conn = new MySqlConnection(Program.ConnectionString);
                MySqlCommand cmd = new MySqlCommand();
                MySqlBackup mb = new MySqlBackup(cmd);
                cmd.Connection = conn;
                conn.Open();
                mb.ImportFromMemoryStream(ms);
                conn.Close();
                MessageBox.Show("Finished.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="caminho"></param>
        /// <returns></returns>
        public bool BackUp(string caminho)
        {
            using (MySqlConnection conn = new MySqlConnection(String.Format(this.conStr, this.HOST, this.USER, this.PASS, this.BASE)))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();

                        try
                        {
                            mb.ExportToFile(caminho);
                            return true;
                        }
                        catch
                        {
                            return false;
                        }
                        finally
                        {
                            conn.Close();
                        }

                    }
                }
            }
        }
Пример #10
0
 public ExportCompleteArgs(DateTime timeStart, DateTime timeEnd, MySqlBackup.ProcessEndType endType, Exception exception)
 {
     _completionType = endType;
     _timeStart = timeStart;
     _timeEnd = timeEnd;
     _timeUsed = timeStart - timeEnd;
     _exception = exception;
 }
Пример #11
0
 /// <summary>
 /// Back up a MySql database to the specified file.
 /// </summary>
 public static void BackupMySqlDb(string path, string conectionString)
 {
     using (MySqlConnection conn = new MySqlConnection(conectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand("", conn))
         {
             conn.Open();
             var backup = new MySqlBackup(cmd);
             backup.ExportToFile(path);
             conn.Close();
         }
     }
 }
Пример #12
0
 /// <summary>
 /// Back up a MySql database from the specified file.
 /// </summary>
 public static void Restore(string path, string conectionString)
 {
     using (MySqlConnection conn = new MySqlConnection(conectionString))
     {
         using (MySqlCommand cmd = new MySqlCommand("", conn))
         {
             conn.Open();
             var backup = new MySqlBackup(cmd);
             backup.ImportFromFile(path);
             conn.Close();
         }
     }
 }
Пример #13
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfBackup = new SaveFileDialog();

            sfBackup.Filter = "sql files (*.sql)|*.sql|All files (*.*)|*.*";
            sfBackup.RestoreDirectory = true;
            //sfBackup.ShowDialog();

            Database dbc = new Database();
            string strconnect = dbc.getString();
            MySqlConnection connect = new MySqlConnection(strconnect);
            connect.Open();
            if (sfBackup.ShowDialog() == DialogResult.OK)
            {
                string filename = "" + sfBackup.FileName + "";

                using (MySqlConnection cn = new MySqlConnection(strconnect))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {

                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = cn;
                            cn.Open();
                            mb.ExportToFile(filename);
                            cn.Close();

                        }

                    }
                }
                try
                {
                    bool backupResult = true;
                    if (backupResult == true)
                    {
                        MessageBox.Show("Sukses Backup Database!", "Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Gagal Backup Database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                catch (SystemException ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public FormRESTORE()
        {
            InitializeComponent();
            mb = new MySqlBackup();
            mb.ImportProgressChanged += mb_ImportProgressChanged;

            timer1 = new Timer();
            timer1.Interval = 50;
            timer1.Tick += timer1_Tick;

            bwImport = new BackgroundWorker();
            bwImport.DoWork += bwImport_DoWork;
            bwImport.RunWorkerCompleted += bwImport_RunWorkerCompleted;
        }
Пример #15
0
 private void cmdExport_Click(object sender, EventArgs e)
 {
     try
     {
         MySql.Data.MySqlClient.MySqlBackup mb = new MySql.Data.MySqlClient.MySqlBackup(constr);
         mb.ExportBlobAsFile(txtFolder.Text, cbTable.Text, cbBLOB.Text, cbFileName.Text, cbFileSize.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         return;
     }
     MessageBox.Show("Files have exported successfully and saved to\r\n\r\n" + txtFolder.Text);
 }
Пример #16
0
        private void btExportMemoryZip_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog f = new SaveFileDialog();
                f.Filter = "Zip|*.zip";
                f.FileName = "ZipTest " + DateTime.Now.ToString("yyyyMMdd HHmmss") + ".zip";
                if (f.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                string zipFilePath = f.FileName;
                string zipFileName = "SqlDump.sql";

                using (MemoryStream ms = new MemoryStream())
                {
                    using (TextWriter tw = new StreamWriter(ms, new UTF8Encoding(false)))
                    {
                        using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                        {
                            using (MySqlCommand cmd = new MySqlCommand())
                            {
                                using (MySqlBackup mb = new MySqlBackup(cmd))
                                {
                                    cmd.Connection = conn;
                                    conn.Open();

                                    mb.ExportToTextWriter(tw);
                                    conn.Close();

                                    using (ZipStorer zip = ZipStorer.Create(zipFilePath, "MySQL Dump"))
                                    {
                                        ms.Position = 0;
                                        zip.AddStream(ZipStorer.Compression.Deflate, zipFileName, ms, DateTime.Now, "MySQL Dump");
                                    }
                                }
                            }
                        }
                    }
                }

                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 private void btEncrypt_Click(object sender, EventArgs e)
 {
     try
     {
         using (MySqlBackup mb = new MySqlBackup())
         {
             mb.EncryptDumpFile(txtSource.Text, txtOutput.Text, txtPwd.Text);
         }
         MessageBox.Show("Done");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void btGetHeadersFooters_Click(object sender, EventArgs e)
        {
            using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();

                        txtHeaders.Lines = mb.ExportInfo.GetDocumentHeaders(cmd).ToArray();
                        txtFooters.Lines = mb.ExportInfo.GetDocumentFooters().ToArray();
                    }
                }
            }
        }
        private void button_Backup_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
                return;

            try
            {
                using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        cmd.Connection = conn;
                        conn.Open();

                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            mb.ExportInfo.AddCreateDatabase = cbExAddCreateDatabase.Checked;
                            mb.ExportInfo.ExportTableStructure = cbExAddDropCreateTable.Checked;
                            mb.ExportInfo.ExportRows = cbExExportRows.Checked;
                            mb.ExportInfo.RecordDumpTime = cbExRecordDumpTime.Checked;
                            mb.ExportInfo.ResetAutoIncrement = cbExResetAutoIncrement.Checked;
                            mb.ExportInfo.EnableEncryption = cbExEnableEncryption.Checked;
                            mb.ExportInfo.EncryptionPassword = txtExPassword.Text;
                            mb.ExportInfo.MaxSqlLength = (int)nmExMaxSqlLength.Value;
                            mb.ExportInfo.ExportFunctions = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportProcedures = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportTriggers = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportEvents = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportViews = cbExExportRoutines.Checked;
                            mb.ExportInfo.ExportRoutinesWithoutDefiner = cbExExportRoutinesWithoutDefiner.Checked;
                            mb.ExportInfo.RowsExportMode = (RowsDataExportMode)comboBox_RowsExportMode.SelectedValue;
                            mb.ExportInfo.WrapWithinTransaction = checkBox_WrapInTransaction.Checked;

                            mb.ExportToFile(Program.TargetFile);
                        }
                        conn.Close();
                    }
                }

                MessageBox.Show("Finished. Dump saved at:" + Environment.NewLine + Environment.NewLine + Program.TargetFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #20
0
 public void ImportData()
 {
     string constring = "server=localhost;user=root;pwd=qwerty;database=test;";
     string file = "C:\\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.ExportToFile(file);
                 conn.Close();
             }
         }
     }
 }
Пример #21
0
 public void ExportData()
 {
     string constring = "server=localhost;user=root;pwd=;database=furniture;";
     string file = "sqlbackup.sql";
     using (con = new MySqlConnection(constring))
     {
         using (command = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(command))
             {
                 command.Connection = con;
                 con.Open();
                 mb.ExportToFile(file);
                 con.Close();
             }
         }
     }
 }
Пример #22
0
 public static void exportBackUp(String filename)
 {
     var connection = System.Configuration.ConfigurationManager.ConnectionStrings["admEntities"].ConnectionString;//.Replace("&quot;", "'");
     string constring = connection.Remove(0, connection.IndexOf("server=")).Replace("\"", "");// "server=localhost;user id=root;port=3300;database=adm";// connection;
     string file = filename;
     using (MySqlConnection conn = new MySqlConnection(constring))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ExportToFile(file);
                 conn.Close();
             }
         }
     }
 }
 private void Backup(string sMySQLDatabase, string sFilePath)
 {
     string constring = "server=" + host + ";username="******";password="******";database=" + dbms +
                         ";port=" + port;
     //string file = "C:tempbackup.sql";
     using (MySqlConnection conn = new MySqlConnection(constring))
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             using (MySqlBackup mb = new MySqlBackup(cmd))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 mb.ExportToFile(sFilePath);
                 conn.Close();
             }
         }
     }
 }
        public static void importDataBase()
        {
            try
            {
                // On demande le fichier à l'utilisateur
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Title = "Rechercher un fichier";
                openFileDialog1.FileName = "backup_gestionstock.sql";
                openFileDialog1.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog1.Filter = "SQL files (*.sql)|*.sql|All files (*.*)|*.*";
                openFileDialog1.RestoreDirectory = true;

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        // On affecte le chemin de l'utilisateur et son fichier puis on utilise le fichier pour la restauration
                        string fileimport = openFileDialog1.FileName;

                        // On définit les variables
                        MySqlCommand cmdimport = new MySqlCommand();
                        MySqlBackup mbimport = new MySqlBackup(cmdimport);

                        // On ouvre la connexion, utilise la fonction du package et on ferme la connexion
                        cmdimport.Connection = M_connexion.Gestion;
                        M_connexion.Gestion.Open();
                        mbimport.ImportInfo.DatabaseDefaultCharSet = "utf8";
                        mbimport.ImportFromFile(fileimport);
                        M_connexion.Gestion.Close();
                        MessageBox.Show("Base de données importée." + Environment.NewLine + "A partir du fichier situé dans le chemin : " + fileimport);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erreur: " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Impossible de lire le fichier à partir du disque. Erreur: " + ex.Message);
            }
        }
Пример #25
0
        private void button2_Click(object sender, EventArgs e)
        {
            MySqlConnection conn = new MySqlConnection(Rstring);
            MySqlCommand cmd;
            string s0;

            try
            {
                conn.Open();
                s0 = "CREATE DATABASE IF NOT EXISTS `esalon`;";
                cmd = new MySqlCommand(s0, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                MessageBox.Show("CREATE SUCCESS");
            }
            catch (Exception fe)
            {
                MessageBox.Show(fe.ToString());
            }
            try
            {
                string constring = "server=localhost;user=root;pwd=root;database=esalon;";
                using (MySqlConnection conn1 = new MySqlConnection(constring))
                {
                    using (MySqlCommand cmd1 = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd1))
                        {
                            cmd1.Connection = conn1;
                            conn1.Open();
                            mb.ImportFromFile(file);
                            conn1.Close();
                        }
                    }
                }
                MessageBox.Show("RESTORE SUCCESS");
            }
            catch (Exception fe)
            {
                MessageBox.Show(fe.ToString());
            }
        }
 private void btExport_Click(object sender, EventArgs e)
 {
     try
     {
         MemoryStream ms = new MemoryStream();
         MySqlConnection conn = new MySqlConnection(Program.ConnectionString);
         MySqlCommand cmd = new MySqlCommand();
         MySqlBackup mb = new MySqlBackup(cmd);
         cmd.Connection = conn;
         conn.Open();
         mb.ExportToMemoryStream(ms);
         conn.Close();
         LoadIntoMemory(ms.ToArray());
         MessageBox.Show("Finished.");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Пример #27
0
        private void Export()
        {
            string constring = ConfigurationManager.ConnectionStrings["ERPContext"].ConnectionString;

            using (MySqlConnection conn = new MySqlConnection(constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(filename);
                        mb.ExportInfo.RecordDumpTime = true;
                        conn.Close();
                    }
                    MessageBox.Show("Backup is successful", "Success", MessageBoxButton.OK);
                }
                isDone = true;
            }
        }
Пример #28
0
        protected void btImport(object sender, EventArgs e)
        {
            try
            {
                if (!FileUpload1.HasFile)
                {
                    return;
                }

                byte[] ba = FileUpload1.FileBytes;

                if (FileUpload1.FileName.ToLower().EndsWith(".zip"))
                {
                    MemoryStream ms1 = new MemoryStream(ba);
                    ZipStorer zip = ZipStorer.Open(ms1, FileAccess.Read);
                    List<ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                    MemoryStream ms2 = new MemoryStream();
                    zip.ExtractFile(dir[0], ms2);
                    zip.Close();
                    ba = ms2.ToArray();
                }

                MemoryStream ms3 = new MemoryStream(ba);
                using (MySqlConnection conn = new MySqlConnection(txtConnString.Text))
                {
                    MySqlCommand cmd = new MySqlCommand();
                    MySqlBackup mb = new MySqlBackup(cmd);
                    cmd.Connection = conn;
                    conn.Open();
                    mb.ImportFromMemoryStream(ms3);
                }

                Header.Controls.Add(new LiteralControl("<script type=\"text/javascript\">alert('Import completed.');</script>"));
            }
            catch (Exception ex)
            {
                lbError.Text = ex.Message;
                lbError.Visible = true;
            }
        }
        private void btExport_Click(object sender, EventArgs e)
        {
            if (!Program.TargetDirectoryIsValid())
                return;

            if (checkedListBox1.Items.Count == 0)
            {
                MessageBox.Show("No tables are listed.");
                return;
            }
            try
            {
                List<string> lst = new List<string>();

                foreach (var item in checkedListBox1.CheckedItems)
                {
                    lst.Add(item.ToString());
                }

                using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup mb = new MySqlBackup(cmd))
                        {
                            cmd.Connection = conn;
                            conn.Open();
                            mb.ExportInfo.ExcludeTables = lst;
                            mb.ExportToFile(Program.TargetFile);
                        }
                    }
                }
                MessageBox.Show("Done.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public static void exportDataBase()
        {
            try
            {
                // On demande l'endroit de la sauvegarde à l'utilisateur
                FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        // On affecte le chemin de l'utilisateur et on utilise le fichier pour la sauvegarde
                        string fileexport = folderBrowserDialog1.SelectedPath + "\\backup_gestionstock.sql";

                        // On définit les variables
                        MySqlCommand cmd = new MySqlCommand();
                        MySqlBackup mb = new MySqlBackup(cmd);

                        // On ouvre la connexion, utilise la fonction du package et on ferme la connexion
                        cmd.Connection = M_connexion.Gestion;
                        M_connexion.Gestion.Open();

                        mb.ExportToFile(fileexport);
                        M_connexion.Gestion.Close();
                        MessageBox.Show("Base de données sauvegardée." + Environment.NewLine + "Le fichier se trouve dans le chemin : " + fileexport);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erreur: " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur: " + ex.Message);
            }
        }
Пример #31
0
        protected void btnExportSql_Click(object sender, EventArgs e)
        {
            string constring = ConfigurationManager.ConnectionStrings["clonedeploy"].ConnectionString;
            string exportPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" +
                         Path.DirectorySeparatorChar + "exports" + Path.DirectorySeparatorChar;

            using (MySqlConnection conn = new MySqlConnection(constring))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        mb.ExportToFile(exportPath + "dbDump.sql");
                        conn.Close();
                    }
                }
            }

            EndUserMessage = "Export Complete";


        }