.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

SQL Backup in ASP.NET

Posted By:Athira Sreejith       Posted Date: February 22, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

SQL Backup in ASP.NET Pragmatically. Below is the c# code to do so.

using System;

using System.Data;

using System.Collections;

using Microsoft.SqlServer.Management.Common;

using Microsoft.SqlServer.Management.Smo;

class Program


static void Main(string[] args)


BackupDeviceItem bdi =

new BackupDeviceItem("AdventureWorks.bak", DeviceType.File);

Backup bu = new Backup();

bu.Database = "AdventureWorks";


bu.Initialize = true;

// add percent complete and complete event handlers

bu.PercentComplete +=

new PercentCompleteEventHandler(Backup_PercentComplete);

bu.Complete += new ServerMessageEventHandler(Backup_Complete);

Server server = new Server("localhost");


Console.WriteLine(Environment.NewLine + "Press any key to continue.");



protected static void Backup_PercentComplete(

object sender, PercentCompleteEventArgs e)


Console.WriteLine(e.Percent + "% processed.");


protected static void Backup_Complete(object sender, ServerMessageEventArgs e)


Console.WriteLine(Environment.NewLine + e.ToString());




Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend