从C#和重新导入导出一个SQL Server数据库 [英] Export a SQL Server database from C# and re-import

查看:163
本文介绍了从C#和重新导入导出一个SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来创建在C#代码中的SQL Server 2008数据库的备份。那么我想这个数据库重新导入到本地数据库服务器,再次使用C#代码。

I'm looking for a way to create a backup of a SQL Server 2008 database in C# code. I then wish to re-import this database to a local database server, again using C# code.

我知道这可以通过SQL Server Management Studio中非常容易做到的,但需要一个自动化的方式来实现这一目标。

I know this can be done via the SQL Server Management Studio very easily, but need an automated way to achieve this.

推荐答案

您想要做的是有一对夫妇使用常规的连接对象,你对从C#主数据库运行的脚本(的SqlConnection 等)。

What you want to do is have a couple of scripts that you run against the master database from C# using the regular connection objects (SqlConnection, etc).

有备份命令和命令来恢复并从文件。所有的,那么你需要做的是管理你的应用程序文件

There are commands to backup and commands to restore to and from a file. All you then need to do is manage the file in your application.

要恢复:

HTTP://博客.sqlauthority.com / 2007/02/25 / SQL-服务器恢复数据库的备份,使用-SQL脚本T-SQL /

备份:

HTTP ://msdn.microsoft.com/en-us/library/ms191304.aspx

还有一个从微软一组DLL来对SQL工作Server数据库不属于ADO.NET提供程序集的一部分。这里是一个覆盖这些教程:

There is also a set of DLLs from Microsoft to work against SQL Server databases that are not part of the ADO.NET provider set. Here is a tutorial covering these:

http://www.codeproject.com/KB/database/SQL_Server_2005_Database.aspx

这篇关于从C#和重新导入导出一个SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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