I am writting an ArcMap-AddIn with vb.net. I get an error when trying to compact my IWorkspace(mdb), the error is:


You tried to open a database, which was already opened by the user 'ADMIN' on Computer 'XXXXXX'. Try it again when the database is available.

On ESRI.ArcGIS.Geodatabase.IDatabaseCompact.Compact() on MyProject.MyClass.CompactGDB(IWorkspace pWS)

How can i access that workspace, which i used before, to compact it?

The Code:

' CompactGDB
    Public Sub CompactGDB(ByVal pWS As IWorkspace)

        Dim pDatabaseCompact As IDatabaseCompact
        If (TypeOf pWS Is IDatabaseCompact) Then
            pDatabaseCompact = CType(pWS, IDatabaseCompact)
            If (pDatabaseCompact.CanCompact) Then
                Catch ex As Exception
                    MessageBox.Show(ex.type & ex.Message & ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try

            End If
        End If

    End Sub

I've got 8 other functions, which work with my workspace.

Any suggestions?

1 Answer 1


Before calling the Compact() method make sure there are not any existing locks on the database. If it is a file geodatabase then open the gdb directory in Windows Explorer and look for LOCK type files, they end in .lock. For personal geodatabase there will be a .ldb file in the directory with the same name as the .mdb. If you have a layer or table from the geodatabase loaded in the map then you will not be able to remove all locks. If another user is accessing the geodatabase then you will not be able to remove all locks. If you are using arcobjects to temporarily access the geodatabase then you need to use good practices and close any geodatabase resources when the calling process ends. This includes releasing all COM objects when you are finished with them.

One way to do this use the methods in the ComReleaser class of the ESRI.ArcGIS.ADF.Connection.Local namespace:

ComReleaser Class

  • I guess i can't just use the ComRealeaser.ReleaseCOMObject(myIWorkspace) to do that?
    – Munchies
    Nov 21, 2012 at 11:24
  • I Tried to use that COMReleaser with all my pointers i'm using, still no success.
    – Munchies
    Nov 21, 2012 at 17:11
  • 1
    Did you confirm it is your machine that is holding the lock? I don't know what your program is doing prior to the compact method but one thing to try is not passing around the workspace pointer. In your case you should be done modifying the geodatabase contents prior to calling CompactGDB(). Release all open pointers and workspace. Also make sure to release any feature cursors,etc that it used. Then open a fresh workspace in the compact function. Nov 21, 2012 at 18:29
  • it worked! I Just created a sub which sets all arcobjects variables to = nothing, justbefore i call compactGDB. Thanks!
    – Munchies
    Nov 22, 2012 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.