简体   繁体   中英

Backup and restore MS SQL database

Situation is simple.
I have application in C# that use MS SQL Database. For some reason i need to add some backup/restore function. I have directly access to MS SQL instance. 直接访问MS SQL实例的权限。

Is there any other simply way to backup database from C#? Maybe some script can create tables, structures and data, that can be use on other machine?

I need to do this only via C# (standard .NET references). No third party applications.

No, there isn't.

If you don't have permissions or even a login to the SQL Server instance, you will not be able to run any sort of BACKUP commands against the database.

Backing up the file system (the mdf, ldf, and ndf's) isn't a sufficient backup strategory for SQL Server.

You can use SMO for this (provided you have the appropriate access permissions):

To run the SqlBackup method, users must have BACKUP DATABASE or BACKUP LOG permissions on the database, or be a member of the db_owner and db_backupoperator fixed database role and the sysadmin fixed server role.

Also:

C# SMO backup of remote database to local machine .

Getting Started with SMO in SQL 2005 - Backups

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM