vendredi 30 janvier 2015

How can I release the lock file on a DBF after removing its join to a FeatureLayer using ArcObjects?


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




Aucun commentaire:

Enregistrer un commentaire