0

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

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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:

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.