Results 1 to 7 of 7

Thread: compacting databases

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    6

    compacting databases

    Hi All,

    I have an MS-ACCESS 2000 databases which need to compacted.
    I know there are only 2 methods: by ADO and by DAO.
    My Q is which method is good in performance and speed wise?
    I tried with both of them but not able to judge which is a better choice.

    Any help is appreciated,
    TIA
    sharat

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    6

    compacting databases

    FYI
    I am using WIN 2000 on NT and VB 6.0

    TIA,
    sharat

  3. #3
    Addicted Member Mandelbrot's Avatar
    Join Date
    Aug 2001
    Location
    Work, as usual!!
    Posts
    241
    You can get Access 2000 databases to self-compact on exit. Have a look in the options (Tools / Options...).

  4. #4
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by oh1mie
    Try this:
    VB Code:
    1. Public Sub subCompactDatabase(DbFile As String, Optional Versio As Integer = 5)
    2.    
    3.    'Add Microsoft Jet and Replication Objects 2.x Library to references
    4.     Screen.MousePointer = vbHourglass
    5.    
    6.     On Local Error Resume Next
    7.        
    8.     Dim strScoreFile       As String
    9.     Dim strScoreFileBackup As String
    10.     Dim JRO               As JRO.JetEngine
    11.    
    12.     strScoreFile = DbFile
    13.     strScoreFileBackup = Left(strScoreFile, Len(strScoreFile) - 3) & "~db"
    14.    
    15.     Kill strScoreFileBackup
    16.     Name strScoreFile As strScoreFileBackup
    17.    
    18.     Set JRO = New JRO.JetEngine
    19.     JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strScoreFileBackup, _
    20.                         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strScoreFile & ";Jet OLEDB:Engine Type=" & Versio
    21.    
    22.     Kill strScoreFileBackup
    23.     Screen.MousePointer = vbDefault
    24.    
    25. End Sub
    Quick question. How can I find the file size of the database before I compacted it and then grab it again after compacting it?
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  5. #5
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    You can use Api:
    VB Code:
    1. Option Explicit
    2.  
    3. Public Const MAX_PATH As Long = 260
    4. Public Const INVALID_HANDLE_VALUE As Long = -1
    5.  
    6. Public Type FILETIME
    7.    dwLowDateTime  As Long
    8.    dwHighDateTime As Long
    9. End Type
    10.  
    11. Public Type WIN32_FIND_DATA
    12.    dwFileAttributes As Long
    13.    ftCreationTime   As FILETIME
    14.    ftLastAccessTime As FILETIME
    15.    ftLastWriteTime  As FILETIME
    16.    nFileSizeHigh    As Long
    17.    nFileSizeLow     As Long
    18.    dwReserved0      As Long
    19.    dwReserved1      As Long
    20.    cFileName        As String * MAX_PATH
    21.    cAlternate       As String * 14
    22. End Type
    23.  
    24. Public Declare Function FindFirstFile Lib "kernel32" _
    25.    Alias "FindFirstFileA" _
    26.   (ByVal lpFileName As String, _
    27.    lpFindFileData As WIN32_FIND_DATA) As Long
    28.  
    29. Public Declare Function FindClose Lib "kernel32" _
    30.   (ByVal hFindFile As Long) As Long
    31. Public Function fcnFileSize(TargetFile As String) As Long
    32.    
    33.    On Local Error Resume Next
    34.  
    35.    Dim WFD As WIN32_FIND_DATA
    36.    Dim hFile As Long
    37.    
    38.    hFile = FindFirstFile(TargetFile, WFD)
    39.    If hFile <> INVALID_HANDLE_VALUE Then
    40.       fcnFileSize = WFD.nFileSizeLow
    41.    End If
    42.    Call FindClose(hFile)
    43.    
    44. End Function
    oh1mie/Vic


  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    I ended up just making a copy of the database file as an option instead of compacting the database. For some reason I kept getting too old of a version error or something.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    San Jose, Ca. - USA
    Posts
    302
    thought this might also be of some help.

    http://www.gab2001uk.com/visualbasic/daovsado/index.htm

    this site proves that DAO is about 3 times faster than ADO.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width