1

I found another post with two different answers on how to remove the join between a feature layer and a standalone table, but neither method successfully removes the lock file (filename.dbf.COMPUTERNAME.####.####.sr.lock) as viewed in Windows explorer. I'm testing this by creating the join in ArcMap via right-clicking on a feature layer and creating a join through the Joins and Relates context menu item. The join is between a feature class in a personal and/or file geodatabase and a DBF table (not a shapefile). The DBF table is not loaded in the TOC.

Actually, Kirk's method may work but as it's written it produces an exception, and when "fixed" it (RemoveJoins1 below) the code runs but the join remains (and consequently the lock also remains). The other answer (RemoveJoins2 below) that uses IDisplayRelationshipClass successfully removes the join, but the lock file still remains.

Additional info: if I remove the join using the Joins and Relates context menu item and don't remove it using ArcObjects, then the lock file is released. So something in the code sample is causing ArcMap to keep the lock file even though the join is removed.

Any ideas how the lock file can be removed/released?

Public Sub RemoveJoins1(ByVal joinedLayer As IFeatureLayer)
    Dim dTable As IDisplayTable = CType(joinedLayer, IDisplayTable)
    Dim rqTable As IRelQueryTable = TryCast(dTable.DisplayTable, IRelQueryTable)
    If Not rqTable Is Nothing Then
        Debug.Print("source: {0}", CType(rqTable.SourceTable, IDataset).Name)
        Debug.Print("dest: {0}", CType(rqTable.DestinationTable, IDataset).Name)
        joinedLayer.FeatureClass = CType(rqTable.SourceTable, IFeatureClass)
    Else
        Debug.Print("there are no joins")
    End If
End Sub

Public Sub RemoveJoins2(ByVal joinedLayer As IFeatureLayer)
    Dim dTable As IDisplayTable = CType(joinedLayer, IDisplayTable)
    Dim rqTable As IRelQueryTable = TryCast(dTable.DisplayTable, IRelQueryTable)
    If Not rqTable Is Nothing Then
        Debug.Print("source: {0}", CType(rqTable.SourceTable, IDataset).Name)
        Debug.Print("dest: {0}", CType(rqTable.DestinationTable, IDataset).Name)

        Dim drClass As IDisplayRelationshipClass = CType(joinedLayer, IDisplayRelationshipClass)
        Dim rqTableInfo As IRelQueryTableInfo = CType(rqTable, IRelQueryTableInfo)
        drClass.DisplayRelationshipClass(Nothing, esriJoinType.esriLeftInnerJoin)
    Else
        Debug.Print("there are no joins")
    End If
End Sub
5
  • I've previously deleted lock files via Windows explorer without problems.
    – Emily
    Jan 29, 2015 at 21:54
  • Though I have deleted lock files with Windows explorer in the past, that was generally when the lock file remained erroneously. In this case, it seems that ArcMap is somehow still holding on to the file, but I'm not sure how or why.
    – isburns
    Jan 29, 2015 at 22:32
  • Just thinking aloud have you tried calling the remove join geoprocessing tool using the IGeoprocessor?
    – Hornbydd
    Jan 30, 2015 at 0:06
  • @Hornbydd Haven't tried the Geoprocessor yet, I'll give that a shot.
    – isburns
    Jan 30, 2015 at 16:05
  • @Hornbydd, Your suggestion worked, however the geoprocessor is quite slow in comparison to the RemoveJoins2 method, but I guess I'll have to live with that. Anyway, thanks for the suggestion.
    – isburns
    Feb 2, 2015 at 23:29

1 Answer 1

1

Thanks to the comment from Hornbydd, I tried using the Geoprocessor to remove the join and the lock file did disappear (see RemoveJoins3). I would still like to understand why the lock file isn't being released using the other methods (and get some input from Kirk Kuykendall on why his method I linked to doesn't work for me). I would also like a solution that doesn't use the Geoprocessor because it's notably slower then the RemoveJoins2 method.

Public Sub RemoveJoins3(ByVal joinedLayer As IFeatureLayer)
    Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
    Dim removeJoinTool As New ESRI.ArcGIS.DataManagementTools.RemoveJoin
    removeJoinTool.in_layer_or_view = joinedLayer
    GP.Execute(removeJoinTool, Nothing)
End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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