- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安ASP维护基地 来源:黑客防线网安ASP维护基地 浏览次数:0 |
else
{
dbName = txtDbName.Text.Trim();
}
string SqlStr1 = "Data Source=.\sqlexpress;Initial Catalog='" + dbName + "';Integrated Security=True";
string SqlStr2 = @"use master restore database " + dbName + " from disk='" + path + "'";
SqlConnection con = new SqlConnection(SqlStr1);
con.Open();
try
{
SqlCommand com = new SqlCommand(SqlStr2, con);
com.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('还原数据成功!');'</script>");
}
catch (Exception error)
{
Response.Write(error.Message);
Response.Write("<script language=javascript>alert('还原数据失败!')</script>");
txtDbName.Text = SqlStr2;
}
finally
{
con.Close();
}
}
/// <summary>
/// 恢复数据库,可选择是否可以强制还原(即在其他人在用的时候,依然可以还原)
/// </summary>
/// <param name="databasename">待还原的数据库名称</param>
/// <param name="databasefile">带还原的备份文件的完全路径</param>
/// <param name="errormessage">恢复数据库失败的信息</param>
/// <param name="forceRestore">是否强制还原(恢复),如果为TRUE,则exec killspid '数据库名' 结束此数据库的进程,这样才能还原数据库</param>
/// <returns></returns>
public bool RestoreDataBase(string databasename, string databasefile, ref string returnMessage, bool forceRestore, SqlConnection conn)
{
bool success = true;
string path = databasefile;
string dbname = databasename;
string restoreSql = "use master;";
if (forceRestore)//如果强制回复
restoreSql += string.Format("use master exec killspid '{0}';", databasename);
restoreSql += "restore database @dbname from disk = @path;";
SqlCommand myCommand = new SqlCommand(restoreSql, conn);
myCommand.Parameters.Add("@dbname", SqlDbType.Char);
myCommand.Parameters["@dbname"].Value = dbname;
myCommand.Parameters.Add("@path", SqlDbType.Char);
myCommand.Parameters["@path"].Value = path;
Response.Write(restoreSql);
try
{
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
returnMessage = "还原成功";
}
catch (Exception ex)
{
returnMessage = ex.Message;
success = false;
}
finally
{
myCommand.Connection.Close();
}
return success;
}
protected void Button3_Click(object sender, EventArgs e)
{
string path = this.FileUpload1.PostedFile.FileName; //获得备份路径及数据库名称
string dbName = string.Empty;
if (DropDownList1.Items.Count != 0)
{
dbName = DropDownList1.SelectedValue.Trim();
}
else
{
dbName = txtDbName.Text.Trim();
}
string returnMessage = string.Empty;
string SqlStr1 = "Data Source=.\sqlexpress;Initial Catalog='
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |