C# 恢复在线数据库

发布于 2024-10-15 07:54:31 字数 1450 浏览 2 评论 0原文

只是另一个问题。

我有一个 C# 项目,具有备份和恢复在线 MySQL 数据库的功能。备份功能运行得很好,但是我似乎无法使恢复功能在线工作。不过,它对于本地数据库来说效果很好。

这是我的恢复功能的代码:

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);
               process.StandardInput.WriteLine(input);
               process.StandardInput.Close();
               process.WaitForExit();
               process.Close();

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

          }
}

任何帮助将不胜感激。谢谢你!

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);
               process.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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2024-10-22 07:54:31

替换 psi.FileName = "mysql";和
psi.FileName = "C:/wamp/bin/mysql/mysql5.5.24/bin/mysql.exe";

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文