日期:2014-05-18 浏览次数:20994 次
else//恢复数据库
{
try
{
if (fulFile.HasFile)
{
SqlCommand command = new SqlCommand("use master;restore database @name from disk=@path;", connection);
connection.Open();
string path = fulFile.PostedFile.FileName; //获取备份文件
command.Parameters.AddWithValue("@name", dbName);
command.Parameters.AddWithValue("@path", path);
[color=#FF0000] command.ExecuteNonQuery();[/color]
ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('还原成功!');</script>");
connection.Close();
}
else
{
ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('请先选择备份的文件位置!');</script>");
}
}
catch (Exception ex)
{
ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('还原数据库失败!原因是:"+ex.Message+"');</script>");
}
}