Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

COMException

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
                Try
                    pDatabaseCompact.Compact()
                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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
I guess i can't just use the ComRealeaser.ReleaseCOMObject(myIWorkspace) to do that? –  Munchies Nov 21 '12 at 11:24
    
I Tried to use that COMReleaser with all my pointers i'm using, still no success. –  Munchies Nov 21 '12 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. –  Rich Wawrzonek Nov 21 '12 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 '12 at 15:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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