Export a SQL Server database from C# and re-import

前端 未结 3 1918
野的像风
野的像风 2021-01-13 18:52

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. <

3条回答
  •  花落未央
    2021-01-13 19:40

    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.

    To restore:

    http://blog.sqlauthority.com/2007/02/25/sql-server-restore-database-backup-using-sql-script-t-sql/

    To backup:

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

    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

提交回复
热议问题