在 ArcGIS Engine 中编辑 Blob 字段时出错

发布于 2024-08-10 08:25:01 字数 1085 浏览 9 评论 0原文

我有一个由 MSSQL 数据库支持的 GIS 图层。例如,图层上的要素具有一个 esriFieldTypeString 类型的字段和一个 esriFieldTypeBlob 类型的字段。我可以很好地编辑字符串字段,但是,当我尝试编辑 blob 时,StopEditOperation() 会抛出一个非常通用的异常(消息:“错误 HRESULT E_FAIL 已从对 COM 组件的调用中返回。”,错误代码: -2147467259)。我在服务器日志中找不到任何相关内容。有人知道发生了什么事吗?

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();

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谜兔 2024-08-17 08:25:01

首先,您很可能在 ESRI 论坛上获得更好的反馈,因为您的问题非常具体。

我似乎记得我对 BLOB 也有类似的问题,只读取它们,而不写入它们。就我而言,我使用回收游标来检索功能引用,使用非回收游标解决了这个问题。我认为这不是您的情况,因为您正在执行编辑,这要求您使用非循环光标。或者,您可能直接从图层获取对功能的引用,这根本不涉及您的光标。

您使用 MemoryBlobStream 的 ImportFromVariant 的方式很好,我没有看到任何问题。我首先测试在个人或文件地理数据库中编辑 blob 时是否会出现相同的问题。

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.

痴者 2024-08-17 08:25:01

尝试从编辑会话中获取该功能。

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

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

放弃对在编辑会话边界(在 StartEditing 上)检索的行对象的所有引用。如果对行对象的引用将在编辑操作中保留,则丢弃所有引用并重新获取对象。

另请尝试以下建议:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文