Greens
Greens

Reputation: 3057

Backup SQL DATABASE with C# 3.0

How do u backup SQL Server db with C# 3.0 ?

Upvotes: 0

Views: 599

Answers (4)

Cody C
Cody C

Reputation: 4797

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

Upvotes: 1

Quintin Robinson
Quintin Robinson

Reputation: 82325

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

Upvotes: 4

SQLMenace
SQLMenace

Reputation: 134923

by executing a backup database command, but this has nothing to do with C#

Upvotes: 0

Andrew Hare
Andrew Hare

Reputation: 351456

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:

Upvotes: 0

Related Questions