C# Express备份/恢复数据库

发布于 2024-11-06 16:31:02 字数 392 浏览 1 评论 0 原文

我完全迷失在这里,我的时间不多了。让我解释一下我的情况:

我用 C#express 2010 和 SQL Server Express 2008 R2 创建了一个软件。

现在,在我的软件的设置部分,用户应该能够手动备份/恢复数据库。

此外,他应该能够安排数据库备份,该备份将在他设置的时间运行。

我不知道如何让这两个工作发挥作用,我希望这里有人能给我指出正确的方向。

  • 我需要能够创建一个 数据库的备份/恢复 单击按钮
  • 我需要能够安排备份 流程

请记住,当用户在他的计算机上安装该软件时,他不会安装 sql server(我这么说是因为我的印象是 SMO 要求在客户端计算机上预先安装 sql server)。

谢谢

I am completely lost here and I am running out of time. Let me explain my situation:

I have created a software in C# express 2010 and SQL Server Express 2008 R2.

Now in the settings section of my software, the user is supposed to be able to make manual back ups/restores of the database.

Also he is supposed to be able to schedule back ups of the database, which will run at time that he will set.

I do not have a clue on how to get both of these working and I am hoping that someone here may point me in the correct direction.

  • I need to be able to create a
    backup/restore of the database from
    the click of a button
  • I need to be able to schedule backup
    processes

Please keep in mind that when the user will install the software on his computer, he will not have sql server installed (I am saying this because I am under the impression that SMO requires sql server to be pre installed on the client machine).

Thank you

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

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

发布评论

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

评论(2

☆獨立☆ 2024-11-13 16:31:02

您随时可以尝试 Google

  1. 备份
  2. 恢复
  3. 使用 .microsoft.com/en-us/library/ms135739.aspx" rel="nofollow">SQL 作业代理

我假设您可以创建 Windows 窗体并连接 OnClick 事件,并对数据库运行 SqlCommand。然后,只需在用户按下适当的按钮时使用上面的文档编写适当的查询即可。

顺便说一句:这是一个问答网站,而不是紧急咨询店。不要说“我没时间了”之类的话,也不要写下大量的需求清单并说告诉我如何做到这一点。这样你绝对不会得到任何帮助。在展示您的努力和具体技术问题后提出具体问题。

You could always try Google.

  1. Backup
  2. Restore
  3. Automate backup scripts using the SQL Job Agent

I'm assuming you can create Windows Forms and wire up OnClick events, and run SqlCommand's against the database. Then it's just a matter of using the documentation above to write the appropriate queries when the user presses the appropriate button.

BTW: This is a Q&A site, not an emergency consultant shop. Don't say things like "I'm running out of time" and don't write up large lists of requirements and say tell me how to do this. You'll get absolutely no help that way. Ask specific questions after demonstrating your effort and specific technical problem.

梦里泪两行 2024-11-13 16:31:02

您可以查看此 C# 示例,了解如何使用 SMO 备份数据库

http://social.msdn.microsoft.com/forums/en-US/sqlexpress/thread/95750bdf-fcb1-45bf-9247-d7c0e1b9c8d2/

另一个选项是运行进程并从代码

http://www.sqldbatips.com/showarticle.asp?ID=27" 调用 sqlcmd ID=27

这是一些执行流程的示例代码

string fileName = @"C:\Backup.sql";

ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S .\SQLExpress -U sa -d mydatabasename -o C:\sqlout.txt -i """ + @fileName + @""" -P");

 info.UseShellExecute = false;

 info.CreateNoWindow = true;

 info.WindowStyle = ProcessWindowStyle.Hidden;

 info.RedirectStandardOutput = true;

 Process p = new Process();

 p.StartInfo = info;

 p.Start();

You could look at this C# example for using SMO to backup the database

http://social.msdn.microsoft.com/forums/en-US/sqlexpress/thread/95750bdf-fcb1-45bf-9247-d7c0e1b9c8d2/

The other option is to run a process and call sqlcmd from code

http://www.sqldbatips.com/showarticle.asp?ID=27

Here is some sample code to execute process

string fileName = @"C:\Backup.sql";

ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S .\SQLExpress -U sa -d mydatabasename -o C:\sqlout.txt -i """ + @fileName + @""" -P");

 info.UseShellExecute = false;

 info.CreateNoWindow = true;

 info.WindowStyle = ProcessWindowStyle.Hidden;

 info.RedirectStandardOutput = true;

 Process p = new Process();

 p.StartInfo = info;

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