Select to view content in your preferred language

UpdateCursor locking file geodatabase

2222
4
04-02-2010 11:56 AM
MikeTischler
Emerging Contributor
Hi,
I'm attempting to perform a query on a featureclass in a file geodatabase and update attribute values for the  features returned from the query on the featureclass.

I'm able to query the FC through Iqueryfilter and get an update cursor.  However, whenever I perform this operation:

Dim updatecursor As IFeatureCursor = pfeatureclass.Update(queryFilter, False)

it appears to lock the featureclass in the file geodatabase, so that I can't set the attribute values later, as:
        Dim pfeat as Ifeature
        pfeat = updatecursor.NextFeature
        pfeat.Value(9) = 121.1
        updatecursor.UpdateFeature(pfeat)

The specific error I'm receiving is on the pfeat.value(9) = 121.1 and is unfortunately not very descriptive:

"Error HRESULT E_FAIL has been returned from a call to a COM component."

Any ideas?  I've tried the few developers examples I've seen, but they aren't much help.
0 Kudos
4 Replies
JamesMacKay
Deactivated User
Hi Michael,

That's a pretty strange error, but I'm a bit skeptical that it's caused by the update cursor. If you retrieve a feature with a known ObjectID (using IFeatureClass.GetFeature) and then try to apply a value using Value(9), does that work?

Also, are you using an edit session and edit operation? These may or may not be necessary depending on the type of data you're working with; for example, editing is required if your feature class participates in a topology. (Granted, this is not the exact behavior I would expect to see in that case either.)

Cheers,
James
0 Kudos
MikeTischler
Emerging Contributor
James,
Yes, as a matter of fact, if I use .getfeature, I can reset the value.  Thanks for that tip!

But, using the cursor still doesn't work.  For what it's worth, a file gets created in my file GDB at this line:

Dim updatecursor As IFeatureCursor = pfc.Update(queryFilter, False)

The file is named "myfc.wr.lock" where 'myfc' is the name of the featureclass in the GDB. 

        Dim updatecursor As IFeatureCursor = pfc.Update(queryFilter, False)
        pfeat = updatecursor.NextFeature
        pfeat.Value(9) = 121.1
        updatecursor.UpdateFeature(pfeat)
0 Kudos
MikeTischler
Emerging Contributor
James,
Yes, as a matter of fact, if I use .getfeature, I can reset the value.  Thanks for that tip!  That method works even after I create and set the featurecursor, too.  So, I guess that means the gdb isn't locked?

But, using the cursor to set the features still doesn't work.  Near as I can figure, the cursor is returning a valid feature.  I can display pfeat.oid after the first .nextfeature call, and I get the correct value for the OID.

Oh, I'm not using and edit session and edit operation.  I don't believe the FC participates in any topology...it's just a bunch of simple point features.

For what it's worth, a file gets created in my file GDB at this line:

Dim updatecursor As IFeatureCursor = pfc.Update(queryFilter, False)

The file is named "myfc.wr.lock" where 'myfc' is the name of the featureclass in the GDB.   That's what was making me think the GDB was being locked.  The code block is below.



        Dim pfeat as IFeature
        Dim updatecursor As IFeatureCursor = pfc.Update(queryFilter, False)
        pfeat = updatecursor.NextFeature
        pfeat.Value(9) = 121.1
        updatecursor.UpdateFeature(pfeat)
0 Kudos
MikeTischler
Emerging Contributor
James,
I think I've identified the problem. 

I was setting the queryfilter to only return a few subfields.  The field which I was updating was NOT one of the ones included in the subfieds property.

Only myself to blame for this one...thanks for the help, though!

mike
0 Kudos