Results 1 to 4 of 4

Thread: Compacting an Access db with VB

  1. #1

    Thread Starter
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273

    Compacting an Access db with VB

    Guys, I know there are tons of threads related to this issue, and I've chased several of them without getting an answer, so:

    I'd like to compact an Access 2000 db from within my application, using the CompactDatabase method of the MS Jet & Replication Objects 2.x library.

    When I execute the method, I'm getting this error:
    "You attempted to open a database that is already opened exclusively by user 'Admin' on machine 'COMPUTER'. Try again when the database is available."

    I DON'T use bound controls. There are no open connections (I only open connections to create disconnected recordsets and then close the connection [all ADO]).

    My questions are:

    1. Is there any way to shut down ALL open connections that may be lurking so that the compact method can get Admin access,

    2. Is the only way to handle this is by writing a separate DB Admin application that can be executed outside of my app?

    Thanks in advance for any responses.

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    I never had any problem with this procedure
    VB Code:
    1. Public Sub subCombactDatabase(DbFile As String, Optional Versio As Integer = 5, Optional LocaleIdentifier As Integer = 1035)
    2.  
    3.     Screen.MousePointer = vbHourglass
    4.    
    5.     On Local Error Resume Next
    6.        
    7.     Dim strFile       As String
    8.     Dim strFileBackup As String
    9.     Dim JRO           As JRO.JetEngine
    10.    
    11.     strFile = DbFile
    12.     strFileBackup = Left(strFile, Len(strFile) - 3) & "~db"
    13.    
    14.     Kill strFileBackup
    15.     Name strFile As strFileBackup
    16.    
    17.     Set JRO = New JRO.JetEngine
    18.     JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileBackup, _
    19.                         "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";Jet OLEDB:Engine Type=" & Versio & ";Locale Identifier=" & LocaleIdentifier
    20.    
    21.     Kill strFileBackup
    22.     Screen.MousePointer = vbDefault
    23.    
    24. End Sub
    oh1mie/Vic


  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I don't know any reliable way of ensuring all db connections have been closed, other than checking for all of them manually. You can call the Close method on all the Connection objects you have used, and set them to Nothing to ensure they are disconnected from the db.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  4. #4

    Thread Starter
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273
    Thanks for the responses.

    oh1mie, that's the code I am trying to use when I get the error.

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