tags:

views:

208

answers:

2

I have a GIS layer backed by a MSSQL db. The features on the layer have, say, one field of type esriFieldTypeString and one of type esriFieldTypeBlob. I can edit the string field just fine, but, when I try to edit a blob, StopEditOperation() throws a very generic exception (message: "Error HRESULT E_FAIL has been returned from a call to a COM component.", error code: -2147467259). I couldn't find anything related in the server log. Does anyone have any idea what's going on?

IServerContext serverContext = GetServerContext(agsConn, serviceName);
ILayer layer = GetILayer(layerName, serverContext);
IWorkspace workspace = GetIWorkspace(layer);

var feature = GetIFeature(objectId, workspace, layer);

var workspaceEdit = (IWorkspaceEdit)workspace;
workspaceEdit.StartEditing(false);
workspaceEdit.StartEditOperation();

var index = feature.Fields.FindField(featureDetailName);
IField field = feature.Fields.get_Field(index);
byte[] byteArray = {1, 2, 3};
MemoryBlobStream blob = new MemoryBlobStream();
((IMemoryBlobStreamVariant)blob).ImportFromVariant(byteArray);
if (field.CheckValue(blob))
{
    feature.set_Value(index, blob);
}

feature.Store();

workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);

serverContext.RemoveAll();
serverContext.ReleaseContext();
A: 

First, you are probably very likely to get better feedback on ESRI forums as your problem is very specific.

I seem to remember I had similar issues with BLOBs, reading them only, not writing to them. In my case I was using a recycling cursor to retrieve the feature references, using a non-recycling cursor solved it. I assume this is not your case as you are performing edits, which requires you to use a non-recycling cursor. Or perhaps you are getting references to your features directly from the layer, which involves no cursors on your part at all.

The way you are using MemoryBlobStream's ImportFromVariant is just fine, I do not see any problems with that. I would first test whether the same problem occurs when editing a blob inside a personal or a file geodatabase.

petr k.
I tried their forums first, but with no luck so far.
Victor Grigoriu
A: 

Try getting the feature from within your edit session.

var workspaceEdit = (IWorkspaceEdit)workspace;
workspaceEdit.StartEditing(false);
workspaceEdit.StartEditOperation();
var feature = GetIFeature(objectId, workspace, layer);

From http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeoDatabase/IWorkspaceEdit.htm

Discard all references to row objects retrieved at the edit session boundary (on StartEditing). If references to row objects will be maintained across edit operations then discard all references and refetch objects..

Also try the suggestion at the end of:

http://forums.esri.com/Thread.asp?c=158&f=2281&t=241561

geographika