// 备份数据 BACKUP DATABASE
void CAboutDlg::OnBtnbackup()
{
CString strSQL;
UpdateData(TRUE);
if (m_backupfile=="")
{
MessageBox("备份文件名为空!","提示",MB_ICONERROR|MB_OK);
return;
}
strSQL = "BACKUP DATABASE hbmobiledb TO DISK ='" + m_backupfile+"'";
GetDlgItem(IDC_BTNBACKUP)->EnableWindow(FALSE);
if (ExecCMD(strSQL))
MessageBox("数据备份成功!","提示",MB_ICONINFORMATION|MB_OK);
GetDlgItem(IDC_BTNBACKUP)->EnableWindow(TRUE);
}
// 恢复数据库
void CAboutDlg::OnBtnrestore()
{
// 断开连接
DisconnectDB();
CString strSQL;
UpdateData(TRUE);
if (m_restorefile=="")
{
MessageBox("备份文件名为空!","提示",MB_ICONERROR|MB_OK);
return;
}
if (MessageBox("恢复操作将会覆盖现有数据,请确认是否要进行恢复?","提示"
,MB_ICONQUESTION|MB_OKCANCEL) == IDCANCEL)
{
return;
}
GetDlgItem(IDC_BTNRESTORE)->EnableWindow(FALSE);
strSQL = "RESTORE DATABASE hbmobiledb FROM DISK = '" + m_restorefile
+ "' with replace";
// 用master进行连接
ConnectDB("master");
//执行RESTORE DATABASE
if (ExecCMD(strSQL))
{
DisconnectDB();
ConnectDB(g_sDataBase);
MessageBox("数据恢复成功!","提示",MB_ICONINFORMATION|MB_OK);
}
else
{
MessageBox("数据库正在使用中,数据恢复失败。请重新启动SQLSERVER服务!","提示",MB_ICONERROR|MB_OK);
}
GetDlgItem(IDC_BTNRESTORE)->EnableWindow(TRUE);
}