简体   繁体   中英

Backup SQL DATABASE with C# 3.0

您如何使用C#3.0备份SQL Server数据库?

You can use SQL SMO to backup the database and perform other SQL functions through c#.

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

You can call the "BACKUP DATABASE" SQL command using a SQL Command Object. You should be able to find some documentation but here is some basic syntax I found

Example

BACKUP DATABASE [Master] TO  [MasterDevice] WITH  
RETAINDAYS = 5, NOFORMAT, INIT,  NAME = N'Master-FullBackup', SKIP, NOREWIND, 
NOUNLOAD,  STATS = 10
GO

Syntax BACKUP DATABASE {database_name | @database_name_var} TO [,...n] [WITH [BLOCKSIZE = {blocksize | @blocksize_variable}] [[,] DESCRIPTION = {text | @text_variable}] [[,] DIFFERENTIAL] [[,] EXPIREDATE = {date | @date_var} | RETAINDAYS = {days | @days_var}] [[,] FORMAT | NOFORMAT] [[,] {INIT | NOINIT}] [[,] MEDIADESCRIPTION = {text | @text_variable}] [[,] MEDIANAME = {media_name | @media_name_variable}] [[,] [NAME = {backup_set_name | @backup_set_name_var}] [[,] {NOSKIP | SKIP}] [[,] {NOUNLOAD | UNLOAD}] [[,] [RESTART] [[,] STATS [= percentage]] ]

You don't - C# is a programming language and as such is unsuitable for database maintenance. The .NET Framework has an API that will allow you to work with a SQL Server database but even this is not the best way to do database maintenance.

SQL Server has a rich array of tools that can be used for backing up a database. Please see these links for more information:

通过执行备份数据库命令,但这与C#无关

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