Access Datenbank komprimieren



  • Hallo Zusammen,

    ich trage gerade einen harten Kampf mit einer Access Datenbank aus.
    Bis jetzt stehts 2:0 für Access 🙄 .
    Mein Problem ist, dass ich eine Datenbank komprimieren möchte.
    Dies funktioniert zwar, ist aber bei manchen db's ewig langsam
    (ca. 15 Sekunden). Wenn ich dieselbe db dann mit Access 2010 öffne
    und komprimiere, dann dauert das ganze höchstens eine Sekunde.

    Bis jetzt habe ich folgende zwei Methoden versucht:

    #include "odbcinst.h" 
    
       // Source String zum komprimieren zusammenbauen
       CString strSource;
       strSource.Format(_T("COMPACT_DB=\"D:\\db.mdb\" \"D:\\dbTmp.mdb\" General"), strDbQuell, strTempDB );
    
       // Datenbank komprimieren
       HWND hWnd = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
    
       // CString strTreiberName = _T("Microsoft Access Driver (*.mdb, *.accdb)");   <--- Mit diesem Treiber funktioniert's gar nicht
       CString strTreiberName = _T("Microsoft Access Driver (*.mdb)");
    
       const BOOL bKomprimierenOk = SQLConfigDataSource(  hWnd,
                                                          ODBC_ADD_SYS_DSN,
                                                          strTreiberName,
                                                          strSource);
    

    Und:

    #include "afxdao.h"
    
          AfxDaoInit();
          CDaoWorkspace::CompactDatabase( _T("D:\\db.mdb"), _T("D:\\dbTmp.mdb") );
          AfxDaoTerm();
    

    Das Ergebnis ist beides mal das selbe. Es komprimiert zwar,
    dauert aber ewig. Die Probleme treten auf, seit Windows 7
    und Office 2010. Mit Xp gab es keine Probleme.
    Ich Benutze Office 2010 und Windows 7 (aktuelle Version).

    Kann mir einer von euch da evtl. einen Tipp geben? wäre super!!!

    Vielen Dank
    Ulli



  • Hallo,

    habe inzwischen eine Lösung gefunden die so aussieht:

    #import <ACEDAO.dll> rename( "EOF", "AdoNSEOF")
    
    // Create an instance of the engine
       DAO::_DBEngine* pEngine = NULL;
    
       // The CoCreateInstance helper function provides a convenient shortcut by connecting 
       // to the class object associated with the specified CLSID, creating an 
       // uninitialized instance, and releasing the class object. 
       HRESULT hr = CoCreateInstance(__uuidof(DAO::DBEngine),
                                     NULL,
                                     CLSCTX_ALL,
                                     IID_IDispatch,
                                     (LPVOID*)&pEngine);
    
       if (SUCCEEDED(hr) && pEngine)
       {
             // COM errors are handled by C++ try/catch block
             try
             {
                hr = pEngine->CompactDatabase( (_bstr_t) _T("D:\\db.mdb"), (_bstr_t)_T("D:\\dbTmp.mdb") );
             }
             catch(_com_error& e)
             {
                TRACE( _T("No success :-( ") );     
             }
    
             pEngine->Release();
             pEngine = NULL;
       }
    

    Dieser Artikel enthällt viele Nützliche Infos zu dem Thema:

    http://msdn.microsoft.com/en-us/library/office/ff965871(v=office.14).aspx#DataProgrammingWithAccess2010_Performance

    Gruß Ulli


Anmelden zum Antworten