Problem: The .ldb file remains when you delete a Geometric Network


When you use VBA and attempt to delete a Geometric Network in a Personal Geodatabase, the .ldb file remains on disk.


ArcMap has a lock on the schema.

Solution or Workaround

Use ISchemaLock::ChangeSchemaLock to release the lock.

Dim pWorkspace As IWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pDataset As IDataset
Dim pGeomNetCol As INetworkCollection
Dim pGeomNet As IGeometricNetwork
Dim pFeatureDataset As IFeatureDataset

Set pWorkspaceFactory = New AccessWorkspaceFactory

' Montgomery.mdb installs with the ArcGIS sample data
Set pWorkspace = pWorkspaceFactory.OpenFromFile("C:\Temp\Montgomery.mdb", 0)

Set pFeatureWorkspace = pWorkspace
Set pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset("water")
Set pGeomNetCol = pFeatureDataset

If pGeomNetCol.GeometricNetworkCount > 0 Then

Set pGeomNet = pGeomNetCol.GeometricNetworkByName("Water_Net")
Set pDataset = pGeomNet

' **********
' ISchemaLock::ChangeSchemaLock releases the lock
Dim pSchemaLock As ISchemaLock
Set pSchemaLock = pDataset
pSchemaLock.ChangeSchemaLock (esriSharedSchemaLock)
' **********

Set pGeomNet = Nothing
Set pDataset = Nothing

End If

Set pWorkspace = Nothing
Set pWorkspaceFactory = Nothing
Set pGeomNetCol = Nothing
Set pFeatureWorkspace = Nothing
Set pFeatureDataset = Nothing