.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 >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Database Back up in ASP.NET(Another method)

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

Taking backup of the database dynamically in Asp.Net. Here is another method to do so.

using System;

using System.Collections.Generic;

using System.Collections;

using System.Data;

using System.Text;

using System.Windows.Forms;

using SourceEdge.BaseEntities;

using SourceEdge.BCL;

using SourceEdge.BaseEntities.Model;

using RoadLines.Model;

using System.Data.Sql;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Configuration;

namespace RoadLines

{

public partial class Frm_Databackup : Form

{

public Frm_Databackup()

{

InitializeComponent();

}

private void btnBack_Click(object sender, EventArgs e)

{

exeStoreProcedure();

this.Close();

}

private void btnCancel_Click(object sender, EventArgs e)

{

this.Close();

}

public void exeStoreProcedure()

{

SqlConnection con = null;

try

{

string path = System.Configuration.ConfigurationManager.ConnectionStrings[2].ConnectionString;

con = new SqlConnection(path);

con.Open();

SqlCommand cmd = new SqlCommand("Exec sp_BackupDatabase 'RoadLines','F'");

cmd.CommandTimeout = 120;

cmd.Connection = con;

cmd.ExecuteNonQuery();

MessageBox.Show("Database backup successfull");

}

catch (Exception exp)

{

MessageBox.Show("Database backup Unsuccess");

MessageBox.Show(exp.ToString());

}

finally

{

if (con != null)

{

con.Close();

}

}

}

}

}



     

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