备份与还原ACCESS数据库

catch (Exception error)

1.前台
       <table>
          <tr>
            <td align=”center” colspan=”3″ style=”height:
19px”><strong><span style=”font-size:
12pt”>备份与回复ACCESS数据库</span></strong></td>
            </tr>
            <tr>
                <td style=”width:
192px”>数据库备份名称:</td>
                <td><asp:TextBox ID=”TextBox1″ runat=”server”
Columns=”17″ MaxLength=”17″></asp:TextBox></td>
                <td><asp:Button ID=”Button1″ runat=”server”
OnClick=”Button1_Click” Text=”数据备份” /></td>
            </tr>
            <tr>
                <td style=”width:
192px”>数据库恢复名称:</td>
                <td><asp:DropDownList ID=”DropDownList1″
runat=”server” Width=”153px”></asp:DropDownList></td>
                <td><asp:Button ID=”Button2″ runat=”server”
OnClick=”Button2_Click” Text=”数据复苏” /></td>
            </tr>
        </table>
2.后台

{

using System.IO;
using System.Data.SqlClient;

dbName = txtDbName.Text.Trim();

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TextBox1.Text =
DateTime.Now.ToShortDateString()+DateTime.Now.Hour.ToString() +
“H.mdb”;
            this.DataBindList();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!File.Exists(Server.MapPath(@”~\bakDataBase\” +
TextBox1.Text)))
        {
            File.Copy(Server.MapPath(@”~\App_Data\Test.mdb”),
Server.MapPath(@”~\bakDataBase\” + TextBox1.Text));
            this.DataBindList();
            Response.Write(“数据备份成功!”卡塔尔;
        }
        else
        {
            Response.Write(“备份文件已经存在,请重新命名!!!”卡塔尔(قطر‎;
        }
    }
    public void DataBindList()
    {
        DropDownList1.Items.Clear();
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn(“fileName”, typeof(string)));
        DirectoryInfo dir = new
DirectoryInfo(Server.MapPath(@”~\bakDataBase\”));
        foreach (FileInfo file in dir.GetFiles())
        {
            DataRow dr = dt.NewRow();
            dr[0] = file;
            dt.Rows.Add(dr);
        }
        DropDownList1.DataSource = dt;
        DropDownList1.DataTextField = “fileName”;
        DropDownList1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        File.Copy(Server.MapPath(@”~\bakDataBase\” +
DropDownList1.SelectedItem.Text),
Server.MapPath(@”~\App_Data\Test.mdb”), true);
        Response.Write(“数据苏醒成功!”卡塔尔(قطر‎;
    }
}

title/title

备份与回复ACCESS数据库
宗旨技艺:
File.Copy

if (!IsPostBack)

/tr

string SqlStr2 = Exec sp_helpdb;

td style=width: 100px

string SqlStr2 = @use master restore database + dbName + from disk=’ +
path + ‘;

td style=width: 100px

this.DropDownList1.DataBind();

SqlStr2 = Exec sp_helpdb;

using System.Collections.Generic;

using System.Linq;

asp:TextBox ID=TextBox1 runat=server Font-Size=9pt
Width=117px/asp:TextBox

myCommand.Connection.Close();

form id=form1 runat=server

}

tr

/td

}

SqlDataReader dr = com.ExecuteReader();

dbName = DropDownList1.SelectedValue.Trim();

{

com.ExecuteNonQuery();

com.ExecuteNonQuery();

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

}

con.Close();

string dbName = string.Empty;

this.DropDownList1.DataBind();

/// 恢复生机数据库,可筛选是不是能够防强恢复生机

RestoreDataBase(txtDbName.Text, path, ref returnMessage, true,con);

string SqlStr1 = Data Source=./sqlexpress;Initial Catalog=’ + dbName +
‘;Integrated Security=True;

asp:FileUpload ID=FileUpload1 runat=server Font-Size=9pt Width=190px /

}

try

{

td style=width: 100px

string SqlStr2 = backup database + dbName + to disk=’ +
this.TextBox1.Text.Trim() + .bak’;

td style=width: 100px; height: 21px

try

myCommand.Connection.Open();

/form

/html 后台:

Response.Write(script
language=javascriptalert(‘备份数据退步!’State of Qatar/script卡塔尔(قطر‎;

}

con.Open();

td colspan=3

{

/td

/// /summary

namespace SysSourceMgmt

/asp:DropDownList

/td

string path = databasefile;

tr

/div

34567.cc葡京误乐城,}

body

{

}

{

}

asp:DropDownList ID=DropDownList1 runat=server Font-Size=9pt Width=124px

tr

SqlCommand com = new SqlCommand(SqlStr2, con);

string path = this.FileUpload1.PostedFile.FileName;
//拿到备份路线及数据库名称

dr = com.ExecuteReader();

SqlStr1 = Server=(local);DataBase=master;Uid=sa;Pwd=;

div style=width: 100%; height: 100px

{

}

{

try

table

SqlConnection con = new SqlConnection(SqlStr1);

{

returnMessage = 还原成功;

/// param name=databasename待还原的数据库名称/param

td style=width: 100px

else

finally

return success;

/body

if (DropDownList1.Items.Count != 0)

string dbName = string.Empty;

span style=font-size: 9pt备份名称和职位/span

this.DropDownList1.DataSource = dr;

td

{

tr

dr.Close();

using System.IO;

SqlConnection con = new SqlConnection(SqlStr1);

myCommand.Parameters[@path].Value = path;

{

}

myCommand.Parameters.Add(@path, SqlDbType.Char);

return;

Response.Write(script
language=javascript教程alert(‘此文件已存在,请从新输入!’State of Qatar;location=’Default.aspx’/script卡塔尔(قطر‎;

dbName = txtDbName.Text.Trim();

html xmlns=

} string SqlStr1 = Data Source=./sqlexpress;Initial Catalog=’ + dbName +
‘;Integrated Security=True;

con.Open();

/// param name=forceRestore是或不是免强恢复生机,假诺为TRUE,则exec killspid
‘数据库名’ 甘休此数据库的长河,那样本领还原数据库/param

/// summary

returnMessage = ex.Message;

using System;

Response.Write(restoreSql);

}

restoreSql += restore database @dbname from disk = @path;;

SqlCommand myCommand = new SqlCommand(restoreSql, conn);

td

/table

protected void Button3_Click(object sender, EventArgs e)

%@ Page Language=C# AutoEventWireup=true
CodeBehind=SqlDbMgmt.asp教程x.cs Inherits=SysSourceMgmt.SqlDbMgmt %

txtDbName.Text = SqlStr2;

table

string path = this.FileUpload1.PostedFile.FileName;
//拿到备份路线及数据库名称

/td

Response.Write(returnMessage);

/// param name=errormessage恢复生机数据库失利的消息/param

}

success = false;

葡京娱乐网上娱乐,Response.Write(error.Message);

发表评论

电子邮件地址不会被公开。 必填项已用*标注