通过C#备份/还原Sql Server数据库 [英] Backup/Restore Sql Server Database through C#

查看:192
本文介绍了通过C#备份/还原Sql Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中更新鲜
我正在为单台PC开发基于Windows的应用程序.
后端是Sql Server 2005
如何通过C#以编程方式再次进行备份备份和还原

请帮助

解决方案

有几种方法可以做到这一点-只需阅读文档;)
最简单的方法可能是(不了解更多详细信息),方法是使用BACKUP和RESTORE命令.

  BACKUP   DATABASE  dbName  TO  磁盘 = '  PATH'
还原 数据库 dbName  FROM  磁盘 = '  PATH' 


我认为在问问是否可以做之前,更合适的问题是您是否应该创建一个可以对Sql Server实例执行备份和还原命令的应用程序.
我最初的反应是,为什么要在Sql Server Management Studio拥有一切来控制自动和手动备份与还原的一切时,为什么要这么做.开发许可证只需要50美元.为什么要重新制作轮子(除非这只是一项学术练习).

没有一个适用于所有备份和还原"方案的大小,尝试为每个方案编写代码只会增强我的初衷.另外,还有安全问题....

话虽如此,我敢肯定这是可能的,但我认为这不切实际.


I am fresher in C#
I am developing a Windows Based Application for a Single PC.
Backend is Sql Server 2005
How can I take backup Backup and Restore it again programatically through C#

Please Help

解决方案

There are several ways to do this - just read the documentation ;)
The easiest is probably (without knowing further details) by using the BACKUP and RESTORE commands

BACKUP DATABASE dbName TO DISK = 'PATH'
RESTORE DATABASE dbName FROM DISK = 'PATH'


I think before you ask can you do it a more appropriate question is should you create an app that can execute Backup and Restore commands to a Sql Server instance.

My initial reaction is why would you want to when Sql Server Management Studio has every thing and more to control automatic and manual backups and restores. The dev license is only like 50 bucks. Why recreate the wheel (unless it''s just an academic exercise).

There isn''t a one size fits all Backup and Restore scenario and trying to code for each one only reinforces my initial thought. Plus, there are security concerns....

With that said, I''m sure it''s possible but I don''t think it''s practical.


这篇关于通过C#备份/还原Sql Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆