//备份可以,但是还原不行。。
void CMyDlg::OnBackup() 
{
// TODO: Add your command handler code here

try
{     m_pConnection.CreateInstance("ADODB.Connection");
     CString strConnect="Provider=MSDASQL.1;Persist Security Info=False;Data Source=sql1;Initial Catalog=YWGL1";
     m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
_bstr_t vSQL;
vSQL = "BackUp database YWGL1 to disk= 'D:\\BackUp\\YWGL1.bak'";
m_pConnection->Execute(vSQL,NULL,adCmdText);
AfxMessageBox("备份数据库完成!");
return;
}   
catch(_com_error e)
{
AfxMessageBox(e.Description());
return ;
}
if (m_pRecordset != NULL)
m_pRecordset->Close();
    m_pConnection->Close();
   // 释放环境
  ::CoUninitialize();
}void CMyDlg::OnRestrore() 
{
// TODO: Add your command handler code here
try
{
if (m_pRecordset != NULL)
m_pRecordset->Close();
//    m_pConnection->Close();
   // 释放环境
//   ::CoUninitialize();
 
//   CoInitialize(NULL);
     // AfxOleInit();


m_pConnection.CreateInstance("ADODB.Connection");
   //  CString strConnect="Provider=MSDASQL.1;Persist Security Info=False;Data Source=mm;Initial Catalog=master";
      _bstr_t strConnect="Provider=MSDASQL.1;Persist Security Info=False;Data Source=mm";
 
 m_pConnection->Open(strConnect,"","",adModeUnknown);
_bstr_t vSQL;
vSQL = "restore database YWGL1 from disk= 'D:\\BackUp\\YWGL1.bak'";
m_pConnection->Execute(vSQL,NULL,adCmdText);
AfxMessageBox("还原数据库完成!");
return;
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return ;
}
}

解决方案 »

  1.   

         _bstr_t strConnect="Provider=MSDASQL.1;Persist Security Info=False;Data Source=mm";//到master的连接。。可还是不对啊。。???
      

  2.   

    SQL语句没问题,在查询分析器里可以执行通过。在程序里就不行了 。。
      

  3.   

    网上说是和默认的master数据库连接,然后执行还原操作,可还是错误。呵呵