开发者

C# Restoring an online db

just another question.

I have a C# project that has a functionality of backing-up and restoring an online MySQL database. The back-up function is working well enough however, I can't seem to make the restore function work online. It works well for a local database though.

Here's my code for the restore function:

private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
{
     //restoreFile is an OpenFileDialog
     restoreFile.Title = "Restore Database";
     restoreFile.FileName = "";
     restoreFile.Filter = "MySQL Dump (*.sql)|*.sql";
     DialogResult dr = restoreFile.ShowDialog();

          if (dr == DialogResult.OK)
          {
               string filepath = restoreFile.FileName;
               StreamReader file = new StreamReader(filepath);
               string input = file.ReadToEnd();
               file.Close();

               ProcessStartInfo psi = new ProcessStartInfo();
               psi.FileName = "mysql";
               psi.RedirectStandardInput = true;
               psi.RedirectStandardOutput = false;
               psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}", "uName", "pass", "localhost", "database");
               psi.UseShellExecute = false;

               Process process = Process.Start(psi);
               proces开发者_运维问答s.StandardInput.WriteLine(input);
               process.StandardInput.Close();
               process.WaitForExit();
               process.Close();

               MessageBox.Show("Database was successfully restored!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);

          }
}

Any help would be much appreciated. Thank you!


Replace psi.FileName = "mysql"; with psi.FileName = "C:/wamp/bin/mysql/mysql5.5.24/bin/mysql.exe";

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜