连接数据库Arcserver不关闭服务或是winform不关闭窗体无法显示编辑完毕的数据

来源:互联网 发布:java oracle 读表 编辑:程序博客网 时间:2024/06/14 20:38
地块入库接口开发中,需要在SOE中执行地块插入postgresql数据库,可是在实现过程中发现虽然已经在数据库中插入了数据,可是如果不断开server的服务,数据库里的数据就不能刷新显示出编辑之后的结果。后来在操作完毕的代码后我使用了 System.Runtime.InteropServices.Marshal.ReleaseComObject()方法释放连接的数据库空间,依然无果。
原代码:
                   
                        guid = GetGuid();
                        guidlist.Add(guid);
                        count++;
                        IFeatureCursor feaCursor = pFC.Insert(true);
                        IFeatureBuffer feaBuffer = pFC.CreateFeatureBuffer();
                        feaBuffer.Shape = firstFea.Shape;//
                        object Ntime = DateTime.Now.ToShortDateString().ToString();
                        int idindex = feaBuffer.Fields.FindField("id");//
                        int fieldindex = feaBuffer.Fields.FindField("clsx_id");//
                        int timeindex = feaBuffer.Fields.FindField("createtime");//
                        if (fieldindex >= 0 && timeindex >= 0 && idindex >= 0)
                        {

                            feaBuffer.set_Value(fieldindex, id); feaBuffer.set_Value(timeindex, Ntime); feaBuffer.set_Value(idindex, guid);
                        }
改正之后(红色为新加入部分),在启动编辑之前使用IMultiuserWorkspaceEdit接口创建编辑:

                var workspaceMulti = pSdeWorkspace as IMultiuserWorkspaceEdit;
                var workspaceEdit = pSdeWorkspace as IWorkspaceEdit;
workspaceMulti.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMNonVersioned);
                workspaceEdit.StartEditOperation();
    guid = GetGuid();
                        guidlist.Add(guid);
                        count++;
                        IFeatureCursor feaCursor = pFC.Insert(true);
                        IFeatureBuffer feaBuffer = pFC.CreateFeatureBuffer();
                        feaBuffer.Shape = firstFea.Shape;//
                        object Ntime = DateTime.Now.ToShortDateString().ToString();
                        int idindex = feaBuffer.Fields.FindField("id");//
                        int fieldindex = feaBuffer.Fields.FindField("clsx_id");//
                        int timeindex = feaBuffer.Fields.FindField("createtime");//
                        if (fieldindex >= 0 && timeindex >= 0 && idindex >= 0)
                        {

                            feaBuffer.set_Value(fieldindex, id); feaBuffer.set_Value(timeindex, Ntime); feaBuffer.set_Value(idindex, guid);
                        }
                        workspaceEdit.StopEditOperation();
                        workspaceEdit.StopEditing(true);
即是开启多用户编辑(Non-versioned editing),并在工作空间编辑操作的开始与结束之间使用局部编辑,在一次编辑内进行多个局部具体的数据编辑操作。
   但其实我觉得这是涉及到了ArcSDE的一个叫做版本机制(Versioning)的问题,即是说允许多个用户编辑同一个Geodatabase,将操作保存成快照,然后根据这个机制里的一些规则对更新后数据做处理,在编辑结束后返回更新的数据。在此使用IMultiuserWorkspaceEdit,声明了它不是一个多版本的操作,可能会避免掉这个问题,这也可能与ArcServer的运作方式有关,具体没有深究,但归根结底还是属于AE开发,只是用法做了些调整。