tags:

views:

275

answers:

4

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

A: 

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:

Andrew Hare
A: 

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

SQLMenace
+4  A: 

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

Quintin Robinson
+1  A: 

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

Cody C