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


Top 5 Contributors of the Month
david stephan

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.Devices.Add(bdi);

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");

bu.SqlBackup(server);

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

Console.ReadKey();

}

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:

Responses

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