SQLServer数据库的备份还原
 //备份
//备份
 private void btnBackUp_Click(object sender, System.EventArgs e)
private void btnBackUp_Click(object sender, System.EventArgs e) {
  { DB db=new DB();
   DB db=new DB(); string backupName="SunWebExam";
   string backupName="SunWebExam"; string cmdText=@"BACKUP DATABASE SunWebExam to disk='"+this.textBox1.Text+"' WITH  NOINIT,NOUNLOAD,NAME = N'"+backupName+"',  NOSKIP ,  STATS = 10,  NOFORMAT ";
   string cmdText=@"BACKUP DATABASE SunWebExam to disk='"+this.textBox1.Text+"' WITH  NOINIT,NOUNLOAD,NAME = N'"+backupName+"',  NOSKIP ,  STATS = 10,  NOFORMAT "; try
   try {
   { db.ExecCommand(cmdText);
    db.ExecCommand(cmdText); MessageBox.Show("数据库备份顺利完成!");
    MessageBox.Show("数据库备份顺利完成!"); }
   } catch
   catch {
   { MessageBox.Show("数据备份失败!");
    MessageBox.Show("数据备份失败!"); }
   } }
  }
 //还原
//还原
 private void btnRevert_Click(object sender, System.EventArgs e)
private void btnRevert_Click(object sender, System.EventArgs e) {
  { DB db=new DB();
   DB db=new DB(); string cmdText=@"RESTORE FILELISTONLY from disk='"+this.textBox2.Text+"'";
   string cmdText=@"RESTORE FILELISTONLY from disk='"+this.textBox2.Text+"'";
 try
   try {
   { db.ExecCommand(cmdText);
    db.ExecCommand(cmdText); MessageBox.Show("数据库还原成功!");
    MessageBox.Show("数据库还原成功!"); }
   } catch
   catch {
   { MessageBox.Show("数据库还原失败!");
    MessageBox.Show("数据库还原失败!"); }
   } }
  } 
 
                    
                 
  
 
    
                
            
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号