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());
            }
        }
示例#2
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;
            }
        }