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