备份
代码
//备份数据库
public void beifen()
{
string path = HttpContext.Current.Server.MapPath("App_Data/sqltest1.bak");
string backupstr = "backup database CompanyDB to disk='" + path + "';";
SqlConnection con = new SqlConnection("server=.;User ID=sa;Password=sa");
SqlCommand cmd = new SqlCommand(backupstr, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
con.Close();
}
}
public void beifen()
{
string path = HttpContext.Current.Server.MapPath("App_Data/sqltest1.bak");
string backupstr = "backup database CompanyDB to disk='" + path + "';";
SqlConnection con = new SqlConnection("server=.;User ID=sa;Password=sa");
SqlCommand cmd = new SqlCommand(backupstr, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
con.Close();
}
}