最近做的一個項目因為服務器是在特殊機房上的
前台代碼
<%@ Page Language=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title></title>
</head>
<body>
<form id=
<div>
<table>
<tr>
<td >
<span >操 作 數 據 庫</span>
</td>
<td>
<asp:DropDownList ID=
</asp:DropDownList>
<asp:TextBox ID=
</td>
<td >
</td>
</tr>
<tr>
<td >
<span >備份名稱和位置</span>
</td>
<td >
<asp:TextBox ID=
</td>
<td >
<span >(如D:\beifen)</span>
</td>
</tr>
<tr>
<td colspan=
<asp:Button ID=
</td>
</tr>
</table>
</div>
<div >
<table>
<tr>
<td >
<span >操 作 數 據 庫</span>
</td>
<td>
<asp:DropDownList ID=
</asp:DropDownList>
</td>
<td >
</td>
</tr>
<tr>
<td >
<span >操 作 數 據 庫</span>
</td>
<td >
<asp:FileUpload ID=
</td>
<td >
</td>
</tr>
<tr>
<td colspan=
<asp:Button ID=
<asp:Button ID=
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
後台
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
namespace SysSourceMgmt
{
public partial class SqlDbMgmt : System
{
protected void Page_Load(object sender
{
if (!IsPostBack)
{
try
{
string SqlStr
string SqlStr
SqlConnection con = new SqlConnection(SqlStr
con
SqlCommand com = new SqlCommand(SqlStr
SqlDataReader dr = com
this
this
this
dr
con
SqlStr
SqlStr
con = new SqlConnection(SqlStr
con
com = new SqlCommand(SqlStr
dr = com
this
this
this
dr
con
}
catch (Exception)
{
}
}
}
protected void Button
{
string dbName = string
if (DropDownList
{
dbName = DropDownList
}
else
{
dbName = txtDbName
}
string SqlStr
string SqlStr
SqlConnection con = new SqlConnection(SqlStr
con
try
{
if (File
{
Response
return;
}
SqlCommand com = new SqlCommand(SqlStr
com
Response
}
catch (Exception error)
{
Response
Response
}
finally
{
con
}
}
protected void Button
{
string path = this
string dbName = string
if (DropDownList
{
dbName = DropDownList
}
else
{
dbName = txtDbName
}
string SqlStr
string SqlStr
SqlConnection con = new SqlConnection(SqlStr
con
try
{
SqlCommand com = new SqlCommand(SqlStr
com
Response
}
catch (Exception error)
{
Response
Response
txtDbName
}
finally
{
con
}
}
/// <summary>
/// 恢復數據庫
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
public bool RestoreDataBase(string databasename
{
bool success = true;
string path = databasefile;
string dbname = databasename;
string restoreSql =
if (forceRestore)//如果強制回復
restoreSql += string
restoreSql +=
SqlCommand myCommand = new SqlCommand(restoreSql
myCommand
myCommand
myCommand
myCommand
Response
try
{
myCommand
myCommand
returnMessage =
}
catch (Exception ex)
{
returnMessage = ex
success = false;
}
finally
{
myCommand
}
return success;
}
protected void Button
{
string path = this
string dbName = string
if (DropDownList
{
dbName = DropDownList
}
else
{
dbName = txtDbName
}
string returnMessage = string
string SqlStr
SqlConnection con = new SqlConnection(SqlStr
RestoreDataBase(txtDbName
Response
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12473.html