备份

代码
  //备份数据库
    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();
        }
    }

 

posted @ 2010-10-08 13:18  DODUI  阅读(179)  评论(0编辑  收藏  举报