Friday, September 23

DataBase BackUp in Specific Folder Using Asp.Net

Here is some code for Coping your database in a specific folder:-

 Page Source View:-

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Database.aspx.cs" Inherits="Database" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Size="Large"
            ForeColor="#990000" Height="169px" onclick="Button1_Click" Text="BackUpButton"
            Width="402px" />

Code View:-

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class Database : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
            File.Copy("D:/Demo3tyre/App_Data/shiba.mdf", "E:/Backup/db/shiba.mdf");
            File.Copy("D:/Demo3tyre/App_Data/shiba_log.ldf", "E:/Backup/db/shiba_log.ldf");
            Response.Write("<script>alert('Back Successfully')</script>");

        catch (Exception)


By click on that button You can store our database in a specific folder which is provided by you.
Before that go to server explorer or your management studio and right click on database i,e. shiba(which is my database name) and click on Detach.

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

shibashish mohanty