string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "backup database " + this.DropDownList1.SelectedValue + " to disk='" + this.TextBox1.Text.Trim() + ".bak'";
SqlConnection con = new SqlConnection(SqlStr1);
con.Open();
try
{
if (File.Exists(this.TextBox1.Text.Trim()))
{
Response.Write(" ");
return;
}
SqlCommand com = new SqlCommand(SqlStr2, con);
com.ExecuteNonQuery();
Response.Write(" ");
}
catch (Exception error)
{
Response.Write(error.Message);
Response.Write(" ");
}
finally
{
con.Close();
}
ASP.NET备份恢复Sql Server数据库
最新推荐文章于 2025-12-16 10:29:19 发布
本文提供了一段使用C#进行SQL Server数据库备份的代码示例。该示例通过DropDownList选择目标数据库,并允许用户指定备份文件的位置及名称。代码还包含了异常处理以确保操作的安全性和稳定性。
273

被折叠的 条评论
为什么被折叠?



