VB.NET - cannot lock database table error

519
2
Jump to solution
03-12-2012 05:13 AM
Corbinde_Bruin
Occasional Contributor II
Hi all,

I'm attempting to move a point and have the attached line features move with it. It works the first time, bt the second time I get the error {"The database engine could not lock table 'DELTA_SanitaryLines_SHAPE_Index' because it is already in use by another person or process."}
I guess something I'm leaving something open programmatically as the database isn't physically open anywhere and I'm the only user/programmer on the project.
This is the line it doesn't like:

'Get and move attached sanlines
' We have to look for Sanlines that come into the manhole and also sanlines that leave from the manhole
' We will do this as two separate While loops
'Find San Lines with matching GfkMHto IDs
sanlineQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilter
sanlineQueryFilter.WhereClause = "([GFKmhTo] = " & movedManholeGID & ") OR ([GFKmhFrom] = " & movedManholeGID & ")"

Dim sanlineFeatureCursor As IFeatureCursor = Nothing
sanlineFeatureCursor = sanlineFeatClass.Update(sanlineQueryFilter, False)
sanlineFeature = sanlineFeatureCursor.NextFeature

sanlineFeatureSelection = sanlineFeatLyr
sanlineFeatureSelection.SelectFeatures(sanlineQueryFilter, Carto.esriSelectionResultEnum.esriSelectionResultNew, False)

'Move sanline ToPoint to match location of moved manhole
While Not sanlineFeature Is Nothing
pLine = sanlineFeature.Shape
sanlineGfkMHfromVal = sanlineFeature.Value(sanlineGfkMHfromFld)
If sanlineGfkMHfromVal = movedManholeGID Then
pLine.ToPoint = movedPoint
Else
pLine.FromPoint = movedPoint
End If
lengthsanline = pLine.Length
sanlineFeature.Shape = pLine

sanlineFeature.Value(sanlineINVLENGTHfld) = Math.Round(lengthsanline)

StoreNameAndTime(sanlineFeature, "Edit")

sanlineFeatureCursor.UpdateFeature(sanlineFeature)
sanlineFeature = sanlineFeatureCursor.NextFeature
End While

sanlineFeatureCursor = Nothing

EndEditSession("sanMHmove")
pMap.ClearSelection()
m_focusmap.Refresh()

justPlunked = False

Any Ideas?
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
Anytime you use an ArcObjects cursor (ICursor or IFeatureCursor), you need to release the reference as soon as you're done with it by calling Marshal.FinalReleaseComObject.  The same is true for any IFeature/IRow objects you're using.  If you're using IFeature/IRow objects within a loop, then call FinalReleaseComObject on them before setting the feature/row variable to the next object in the cursor.  You can also use ESRI's ComReleaser class.

Doing this should release any locks on the database.

View solution in original post

0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
Anytime you use an ArcObjects cursor (ICursor or IFeatureCursor), you need to release the reference as soon as you're done with it by calling Marshal.FinalReleaseComObject.  The same is true for any IFeature/IRow objects you're using.  If you're using IFeature/IRow objects within a loop, then call FinalReleaseComObject on them before setting the feature/row variable to the next object in the cursor.  You can also use ESRI's ComReleaser class.

Doing this should release any locks on the database.
0 Kudos
Corbinde_Bruin
Occasional Contributor II
Thank you very much, it works perfectly.
0 Kudos