Results 1 to 6 of 6

Thread: compact a msaccess db

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    208

    Red face compact a msaccess db

    hi..

    can you pls. give me a link on how to compact a msaccess database within vb6 project.

    thanks,

    alexis

  2. #2
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: compact a msaccess db

    use:
    VB Code:
    1. DBEngine.CompactDatabase("xyz.mdb","abc.mdb")

    I think u need to refere DAO in your project...
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  3. #3
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: compact a msaccess db

    Or else Use Microsoft JRO.

    Add a reference to Microsoft Jet and Replication Objects 2.x Library by opening Project Menu. And then use this function
    VB Code:
    1. Public Function compactRepairMDB(ByVal sourceMDBPath As String, ByVal targetMDBPath As String) As Boolean
    2.     Dim jetReplicationObject As JRO.JetEngine
    3.     Set jetReplicationObject = New JRO.JetEngine
    4.     jetReplicationObject.CompactDatabase _
    5.         "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" _
    6.         & sourceMDBPath, "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" _
    7.         & targetMDBPath
    8.     compactRepairMDB = True
    9.     Set jetReplicationObject = Nothing
    10.     Exit Function
    11. CompactErr:
    12.     compactRepairMDB = False
    13. End Function

    You can use this function like this
    VB Code:
    1. JetReplication.compactRepairMDB("C:\db1.mdb", "C:\db2.mdb")
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    208

    Re: compact a msaccess db

    what are the things i should consider?? should the database be closed first?? how would i know if someone is still using the database?? can i check if the ".ldb" exists, does it mean someone is still using the database?? is it reliable??

  5. #5
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: compact a msaccess db

    I think it will gives an error if the file was opened..Handling the error will solve your problem easily rather than checking for ldb file..
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    208

    Re: compact a msaccess db

    ok thanks, i 'll try the code above.

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