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
  • I've previously deleted lock files via Windows explorer without problems. – Brynne Jan 29 '15 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 '15 at 22:32
  • Just thinking aloud have you tried calling the remove join geoprocessing tool using the IGeoprocessor? – Hornbydd Jan 30 '15 at 0:06
  • @Hornbydd Haven't tried the Geoprocessor yet, I'll give that a shot. – isburns Jan 30 '15 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 '15 at 23:29
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
0

From your question I infer that you have added the dbf file to map as a standalone table. When you access the dbf file for joining it to a feautrelayer, arcobject automatically creates a shared lock for the dbf file.

When you remove the join, and you remove the dbf layer in TOC (StandaloneTable), the shared lock must be automatically removed.

I suggest to take a look at this topic of arcobject help. Link

  • Actually, as I mentioned at the end of the first paragraph, the DBF is not loaded in the map. Even if the DBF is added as a standalone table and I remove the join, then remove the table from the map, the lock is still in place. – isburns Jan 29 '15 at 22:30
  • Is it Engine application or an Arcmap extension? Arcmap has long term issue with locks, and it doens't release the lock properly. I have noticed this problem many times. Try to do these steps with Arcmap (no arcobject) and see the results. – Farid Cheraghi Jan 30 '15 at 11:04
  • If it is an engine application, and use the ComReleaser to release the IStandaloneTable.Link – Farid Cheraghi Jan 30 '15 at 11:06
  • It is an ArcMap add-in, and as I mentioned in the post if the join is removed via ArcMap the lock file is removed, it's removing the join via ArcObjects that is the problem. Also note that in RemoveJoins2, a reference to the joined table is not present so there is nothing to release with ComReleaser. – isburns Jan 30 '15 at 16:04

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.