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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

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)
    {
        try
        {
           
            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)
        {

            throw;
        }
    }
}

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.

ShibashishMnty
shibashish mohanty