ASP.Net Backup Data


 

Download:

http://cid-7d608959d854cb28.skydrive.live.com/embedrowdetail.aspx/SourcesCode/WebBackData|_18-09-2008.zip

รูปที่ 1 รูปที่ 2

รูปที่ 3 รูปที่ 4

รูปที่ 5 รูปที่ 6

รูปที่ 7

 

ออกแบบหน้าจอ

รูปที่ 8 

References:

รูปที่ 9

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.SqlServer.Management;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

public partial class _Default : System.Web.UI.Page 
{

   
protected void Page_Load(object sender, EventArgs e)
   
{
       
if (!IsPostBack)
       
{
           
HyperLink1.Visible = false;
       
}
   
}
   
protected void btBackupData_Click(object sender, EventArgs e)
   
{
       
string dbName = txtDBname.Text.Trim () + DateTime.Now.ToString("_ddMMyyyy_HH.mm.ss") + ".bak";
       
string destinationPath = "";

        destinationPath = Server.MapPath("BackData\" + dbName);
       
Backup sqlBackup = new Backup();

        sqlBackup.Action = BackupActionType.Database;
       
sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
       
sqlBackup.BackupSetName = "Archive";

        sqlBackup.Database = txtDBname.Text.Trim () ;

        BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);

        ServerConnection connection = new ServerConnection(txtSvr.Text, txtUser.Text, txtPass.Text );
       
Server svr = new Server(connection);
       
Database db = svr.Databases[txtDBname.Text.Trim ()];

        sqlBackup.Initialize = true;
       
sqlBackup.Checksum = true;
       
sqlBackup.ContinueAfterError = true;

        sqlBackup.Devices.Add(deviceItem);
       
sqlBackup.Incremental = false;

        sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
       
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;

        sqlBackup.FormatMedia = false;
       
sqlBackup.PercentComplete += new PercentCompleteEventHandler(sqlBackup_PercentComplete);
       
sqlBackup.SqlBackup(svr);

        HyperLink1.Visible = true ;
       
HyperLink1.Text = "BackData\" + dbName; ;
       
HyperLink1.NavigateUrl = "BackData\" + dbName;

    }

    void sqlBackup_PercentComplete(object sender, PercentCompleteEventArgs e)
   
{
       
Label1.Text = e.Percent.ToString() + "% backed up";
   
}
}

 

Download:

http://cid-7d608959d854cb28.skydrive.live.com/embedrowdetail.aspx/SourcesCode/WebBackData|_18-09-2008.zip

 

เกี่ยวกับ

Nuchit Atjanawat is a Microsoft MVP, GreatFriends Community Leader, WindowsITPro Columnist(Mr.Nano), Silverlight Business Application Instructor, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession. He has a very good skill over Silverlight, LightSwitch, C#, XAML & Blend. He shares his technical findings, tutorials in his technical blog. Follow his Blog and Facebook page to be updated on latest articles. - Technical Blog: https://janawat.wordpress.com - WindowsITPro Columnist(Mr.Nano): http://windowsitpro.net - The GreatFriends.Biz Community Discussion Board (nano): http://greatfriends.biz - witter: https://twitter.com/janawat - Facebook Page: https://www.facebook.com/nuchit - Instructor: http://bit.ly/GF250-01, http://bit.ly/GF150-02

เขียนใน Web Application

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

In Archive
%d bloggers like this: