Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[2083] Using SQL-DMO To Backup and Verify a Database

Last post 06-06-2005 11:11 AM by jayender.vs. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [2083] Using SQL-DMO To Backup and Verify a Database

    This thread is for discussions of Using SQL-DMO To Backup and Verify a Database.

    • Post Points: 0
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 01-29-2005 2:28 PM In reply to

    • vpolv
    • Not Ranked
    • Joined on 01-29-2005
    • New Member
    • Points 5

    Using SQL-DMO To Backup and Verify a Database

    Hi

    I tried your code, seems it is not working for remote database backup.
    do u have any update version for taking backups.

    thanks
    • Post Points: 0
  • 06-06-2005 11:11 AM In reply to

    BACKUP SQL DATABASE in VC++

    here  the solution for Backup the database in VC++:



    int backup::OnButton1()

    {
       HRESULT hr;
       if FAILED(hr = CoInitialize (NULL))
       {
           //_tprintf(TEXT("CoInitialize Failed\n"));
           return (0);
       }

       LPSQLDMOSERVER pSQLServer = NULL;

       if FAILED(hr = CoCreateInstance(
           CLSID_SQLDMOServer,
           NULL,
           CLSCTX_INPROC_SERVER,
           IID_ISQLDMOServer,
           (LPVOID*)&pSQLServer))
       {
           //_tprintf(TEXT("CoCreateInstance Failed\n"));
           return (0);
       }

       pSQLServer->SetLoginTimeout(10);
       pSQLServer->SetLoginSecure(TRUE);
       
       if FAILED(hr = pSQLServer->Connect((L"ws-45"),(L"sa"),(L"")))
       {
           AfxMessageBox("Backup connection Failed");
           return DisplayError();
       }

       else
       {
           LPSQLDMODATABASES    pDatabases = NULL;
           LPSQLDMODATABASE    pDatabase = NULL;
           LPSQLDMOFILEGROUPS  pFileGroups = NULL;
           LPSQLDMOFILEGROUP    pFileGroup = NULL;
           LONG                lCount = 0;
           LPSQLDMODBFILE        ppDBFile = NULL;
           LPLONG                pRetVal = NULL;
           long    m_datasize;
           CString temp;
           
           float  m_datasizeMB;
           CString datasize;

           SQLDMO_BSTR        strDB;
       //    long *strDB;
       
    //        char* m_str = new char[100];

           //pSQLServer->GetDatabaseCount(&lCount);

           hr = pSQLServer->GetDatabases(&pDatabases);

           for (LONG i = 0; i < 1; i++)
           {
               pDatabases->GetItemByOrd(i, &pDatabase);

               pDatabase->GetName(&strDB);
               
               pDatabase->Release();
               pDatabase->GetSpaceAvailableInMB(&m_datasizeMB);
               pDatabase->GetFileGroups(&pFileGroups);

           
               pDatabase->GetSize(&m_datasize);

           //    pDatabase->GetFileGroupByName(_T("DOTS"),&pFileGroup);
           //    pFileGroup->GetDBFileByOrd(0,&ppDBFile);

           //    temp = m_datasize;
               datasize.Format("%d",m_datasize);
               temp.Format("%d",m_datasizeMB);
               SetDlgItemText(IDC_EDIT1,datasize);
               //AfxMessageBox(datasize);
               
               //AfxMessageBox(temp);
               
               //    sprintf(m_str,"%lf",m_size);

           
           
           //    wprintf(_T("database %s"), strDB);
           //    wprintf(_T(" Total size  %i \n"), m_size);
           //    wprintf(_T("Free space %lf \n"), m_sizeMB);
           }
           
                       
    }

       LPSQLDMOBACKUP pSQLBackup = NULL;

       if FAILED(hr = CoCreateInstance(
           CLSID_SQLDMOBackup,
           NULL,
           CLSCTX_INPROC_SERVER,
           IID_ISQLDMOBackup,
           (LPVOID*)&pSQLBackup))
       {
       //    _tprintf(TEXT("CoCreateInstance Failed\n"));
           return (0);
       }

       LPCONNECTIONPOINTCONTAINER pMyConnectionPointContainer;
       LPCONNECTIONPOINT pMyConnectionPoint;

       CMyBackupSink* pMyBackupSink = new CMyBackupSink();
       pMyBackupSink->AddRef();
       
       if (!pMyBackupSink)
       {
           return(0);
       }

       DWORD dwCookie;

       // ask the connectable object (pSQLBackup) about its outgoing interface,
       // by using QI on IID_IConnectionPointContainer. If fails, this object
       // does not support outgoing interface
       //
       if FAILED(pSQLBackup->QueryInterface(
           IID_IConnectionPointContainer,
           (LPVOID FAR*) &pMyConnectionPointContainer))
       {
           return DisplayError();
       }

       // find the specific outgoing interface IID_ISQLDMOBackupSink and retrieve
       // a pointer to the connectionpoint object. If fails, the object does not
       // support this outgoing interface

       if FAILED(pMyConnectionPointContainer->FindConnectionPoint(
           IID_ISQLDMOBackupSink,
           (LPCONNECTIONPOINT FAR*)&pMyConnectionPoint))
       {
           return DisplayError();
       }

       // establish the connection between the Sink and the ConnectionPoint object.
       // Retrieve a key (cookie) value for terminating the connection later. If
       // this fails, the Sink and ConnectionPoint object do not support the same interface
       
       if (S_OK != (hr = pMyConnectionPoint->Advise((LPUNKNOWN)pMyBackupSink, &dwCookie)))
       {
           return DisplayError();
       }

       if FAILED(hr = pSQLBackup->SetFiles((L"e:\\test123.dmp") ))
       {
           return DisplayError();
       }

       if FAILED(hr = pSQLBackup->SetDatabase((L"dots")))
       {
           return DisplayError();
       }

    //    hr = pSQLBackup->EXEC sp_spaceused ;

       if FAILED(hr = pSQLBackup->SetTruncateLog(SQLDMOBackup_Log_TruncateOnly))
       {
           return DisplayError();
       }


     
    • Post Points: 0
Page 1 of 1 (3 items)