I am writting an ArcMap-AddIn with vb.net. I got 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 compact the used workspace? There are 8 other functions which also used my workspace.
Any suggestions?
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
Found the solution:
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.
Use the ComReleaser Class in ESRI.ArcGIS.ADF.Connection.Local namespace