?? dlgloaddump.cpp
字號:
// DlgLoadDump.cpp : implementation file
//
#include "stdafx.h"
#include "dump.h"
#include "DlgLoadDump.h"
#include "Common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgLoadDump dialog
extern _ConnectionPtr g_pCN;
extern _RecordsetPtr g_pRS;
CDlgLoadDump::CDlgLoadDump(CWnd* pParent /*=NULL*/)
: CDialog(CDlgLoadDump::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgLoadDump)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgLoadDump::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgLoadDump)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CDlgLoadDump, CDialog)
//{{AFX_MSG_MAP(CDlgLoadDump)
ON_BN_CLICKED(IDC_BUTTON_DUMP, OnButtonDump)
ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
ON_CBN_SELCHANGE(IDC_COMBO_DataBase, OnSelchangeCOMBODataBase)
ON_CBN_SELCHANGE(IDC_COMBO_DataBResume, OnSelchangeCOMBODataBResume)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgLoadDump message handlers
BOOL CDlgLoadDump::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
if (FALSE == CreateCN(g_pCN, "master"))
{
ShowError(ERROR_DDL);
return FALSE;
}
CString strError, strName, strSql;
strSql = "select name from master..sysdatabases where name != 'master' and name !='model' and name != 'tempdb' and name != 'sybsystemdb' and name != 'sybsystemprocs'";
//將數(shù)據(jù)庫信息加入控件
if(FALSE != ExecuteSql(strSql, DB_COMMAND_RESULT_READONLY, g_pRS, &strError))
{
while (FALSE == g_pRS->EndOfFile)
{
GetFieldString("Name", &strName);
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->InsertString(-1, strName);
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->InsertString(-1, strName);
g_pRS->MoveNext();
}
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->SetCurSel(0);
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->SetCurSel(0);
}
OnSelchangeCOMBODataBase();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgLoadDump::OnButtonDump()
{
// TODO: Add your control notification handler code here
((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(false);
CString strDataName, strError, strSQL = "";
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetCurSel(), strDataName);
//先切換到Master數(shù)據(jù)庫
strSQL = "use master";
if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
{
MessageBox(strError);
((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(true);
return;
}
//數(shù)據(jù)庫
strSQL = "dump database " + strDataName + " to \"" + "f:\\" + strDataName + ".dat " + "\" ";
if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
{
MessageBox(strError);
((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(true);
return;
}
((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(true);
}
void CDlgLoadDump::OnButtonLoad()
{
// TODO: Add your control notification handler code here
((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(false);
CString strDataName,strError, strSQL = "";
//取得數(shù)據(jù)庫名稱
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetCurSel(), strDataName);
// 1,設(shè)置當(dāng)前數(shù)據(jù)庫的no chkpt on recover, dbo use only, read only 為TRUE
strSQL = "use master";
if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
{
((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(true);
return;
}
//以下是修改數(shù)據(jù)庫名稱的程序
CString strNewName;
strNewName = "dfg";
strSQL = "use master";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "sp_dboption " + strDataName + ", \"single user\", \"true\"";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "use Dump_DB_CR";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "checkpoint";
ExecuteSql(strSQL, DB_COMMAND_RESULT_READONLY, g_pRS, &strError);
strSQL = "sp_renamedb Dump_DB_CR, " + strNewName;
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "use master";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "sp_dboption dfg, \"single user\",\"false\" ";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "use dfg";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "checkpoint";
ExecuteSql(strSQL, DB_COMMAND_RESULT_READONLY, g_pRS, &strError);
/*
strSQL = "sp_dboption " + strDataName + ", \"no chkpt on recover\", \"true\"";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "sp_dboption " + strDataName + ", \"dbo use only\", \"true\"";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "sp_dboption " + strDataName + ", \"read only\", \"true\"";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "dbcc checkdb";
ExecuteSql(strSQL, DB_COMMAND_RESULT_READONLY, g_pRS, &strError);
//2,開始恢復(fù)數(shù)據(jù)庫
strSQL = "load database " + strDataName + " from \"" + "f:\\" + strDataName + ".dat" + "\" ";
if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
{
// 恢復(fù)初始設(shè)置
strSQL = "sp_dboption " + strDataName + ", \"no chkpt on recover\", \"false\"";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "sp_dboption " + strDataName + ", \"dbo use only\", \"false\"";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
strSQL = "sp_dboption " + strDataName + ", \"read only\", \"false\"";
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
MessageBox(strError);
((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(true);
return;
}
//3,恢復(fù)數(shù)據(jù)庫online
strSQL = "online database " + strDataName;
ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(true);
*/
}
void CDlgLoadDump::OnSelchangeCOMBODataBase()
{
// TODO: Add your control notification handler code here
CString strDataName;
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetCurSel(), strDataName);
}
void CDlgLoadDump::OnSelchangeCOMBODataBResume()
{
// TODO: Add your control notification handler code here
CString strDataName;
((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->GetCurSel(), strDataName);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -