C# SQL Server Express 备份和恢复

发布于 2024-12-21 12:07:18 字数 172 浏览 0 评论 0原文

基本上我有一个 Windows 窗体 C# 程序,它使用 SQL Server Express 数据库来存储用户输入的数据。我想添加用户能够备份其数据库,然后将备份或另一个数据库加载到程序数据库中的功能。

如果有人能给我指出正确的方向,比如一篇文章或教程,那就太好了,因为我已经走进了死胡同。

谢谢

Basically I have a windows form C# program that uses a SQL Server Express database to store data entered by the users. I want to add the ability for the user to be able to backup their database and then load a backup or another database into the programs database.

If someone could point me in the right direction like an article or tutorial that would be great, because I have hit a dead end.

Thanks

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

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

发布评论

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

评论(3

心欲静而疯不止 2024-12-28 12:07:18

您有几个选项可以执行此操作:

  1. 在服务器上直接调用备份数据库恢复数据库

  2. 使用 SMO(SQL Server 管理对象)执行备份以编程方式恢复操作。 (具体来说是这个示例

  3. 使用一些第三方实用程序/库.

You have a few options to do this:

  1. On the server directly call BACKUP DATABASE, RESTORE DATABASE commands.

  2. Use SMO (SQL Server Management Objects) to perform the backup restore operations programatically. (Specifically this sample)

  3. Use some third party utility/library.

过潦 2024-12-28 12:07:18

您可能需要考虑使用以下建议:

花开柳相依 2024-12-28 12:07:18

SQL Server 的好处在于,您可以使用 SQL(T-SQL 或其某些变体)完成或多或少的所有操作 - 这很好,因为这意味着可以相对轻松地完成大多数事情,而无需担心(例如)SMO 的可用性,并进一步以合理通用的方式。

第二件好事是,如果您在 SQL Server Management Studio(可以下载 SQL Server Express 的版本)中运行命令,它通常会(当然在备份和还原的情况下)提供让您将脚本保存到文件而不是执行它。

因此,您可以直接使用 SQL Server Management Studio 来确定基于 SQL 的 backu 和 resotre 命令的结构,然后将它们集成到您的应用程序中。

然而,有一个“陷阱”——SQL Server 只会将备份保存到机器可见的驱动器或从该驱动器恢复备份。运行 SQL Server 实例的服务帐户,如果您的应用程序与用户在同一台​​计算机上运行,​​那么几乎肯定不是问题,但如果不是,则可能会出现问题。

The nice thing about SQL Server is that you can do more or less everything with SQL (T-SQL or some variation thereof) - this is nice because it means that it is relatively easy to do most things without having to worry about (for example) the availability of SMO and further in a reasonably generic fashion.

The second nice thing is that if you run a command in SQL Server Management Studio (a version of which can be downloaded for SQL Server Express) it will, more often than not (and certainly in the case of Backup and Restore), offer to let you save the the script to a file instead of executing it.

So, it would be straightforward for you to use SQL Server Management Studio to determine the structure of SQL based backu and resotre commands and from there to integrate those into your application.

There is, however, a "gotcha" - SQL server will only save backups to/restore backups from a drive that is visible to the machine & service account upon which the SQL Server instance is running, almost certainly not an issue if your application is running on the same machine as the user but potentially a problem if they are not.

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