getting update or search cursor in vb.net crashes ArcMap

2046
4
06-08-2011 02:50 PM
KevinAndras
New Contributor II
Here's my code.
        Dim pBasinCur As ICursor
        Try
            pBasinCur = pTable.Update(Nothing, False) 'crash here
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Error message:
+  System.Runtime.InteropServices.COMException {"Exception from HRESULT: 0x8004022D"} System.Runtime.InteropServices.COMException

Search cursor does the same thing.
The table is fine, I'm able to access its properties such as RowCount and fields.
0 Kudos
4 Replies
KevinAndras
New Contributor II
I've done a little more digging - the same table is used at an earlier point in the code - I get 2 cursors from it, a search and an update.  Those work fine.  Then a form is displayed, and when a button is clicked, the same table is loaded again, and then when I get the cursor it crashes.  If I skip the first step and just go to the part where it crashes, it will work fine. 

I've tried setting pTable = nothing, pCursor = nothing - still can't get it to work.
0 Kudos
KenBuja
MVP Esteemed Contributor
This may or may not help in your situation, but you should get into the habit of releasing your cursors when you are finished with them. Read this post about one way to do this.
0 Kudos
KevinAndras
New Contributor II
Thanks, I'll look into that.
I just solved the problem by adding
gc.Collect
at the end of the code where the first cursors are used.  No more crash.

Is that good enough in general, or is releasing COM objects superior?
0 Kudos
AlexanderGray
Occasional Contributor III
esri ComReleaser or interop marshalcomrelease release just your cursor so I would consider that superior.  GC.Collect is a resource intensive process and doesn't always release the locks you might have on a file or database.  So if the problem was too many still open cursors then yeah, I would say comreleaser is 'superior', kind of how scalpel is 'superior' to a chain saw for performing surgery but not for cutting trees.
0 Kudos