1

I want to update enabled field of feature in an asp.net MVC application. I have below code but it returned "No update session in progress" error

public string Test()
        {
            IWorkspace workSpace = SdeUtil.rtnWorkSpace(UserEnviromentSetting.UserName.ToUpper());
            IWorkspaceEdit workSpaceEdit = workSpace as IWorkspaceEdit;
            var featureWorkspace = workSpace as IFeatureWorkspace;
            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("DISCNT_S");
            var feature = featureClass.GetFeature(4801);
            workSpaceEdit.StartEditing(true);
            workSpaceEdit.StartEditOperation();
            var enableInd = feature.Fields.FindField("ENABLED");
            feature.set_Value(enableInd, 0);
            feature.Store();
            workSpaceEdit.StopEditOperation();
            workSpaceEdit.StopEditing(true);
            return "s";
        }

Even if I use below code it returned "Objects in this class cannot be updated outside an edit session"

IWorkspace workSpace = SdeUtil.rtnWorkSpace(UserEnviromentSetting.UserName.ToUpper());
            IWorkspaceEdit workSpaceEdit = workSpace as IWorkspaceEdit;
            var featureWorkspace = workSpace as IFeatureWorkspace;
            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("DISCNT_S");
            workSpaceEdit.StartEditing(true);
            workSpaceEdit.StartEditOperation();
            IQueryFilter filter = new QueryFilterClass();
            filter.WhereClause = "OBJECTID = 4801";
            var featureCursor = featureClass.Update(filter, false);
            var feature = featureCursor.NextFeature();
            if (feature != null)
            {
                var enableInd = feature.Fields.FindField("ENABLED");
                feature.set_Value(enableInd, 0);
                feature.Store();
            }
            workSpaceEdit.StopEditOperation();
            workSpaceEdit.StopEditing(true);
            return "s";

rtnWorkspace mthod is:

public static IWorkspace rtnWorkSpace(string versionName, string serviceName, string userName, string userPass)
        {
            string sSERVER = string.Empty;
            string sInstance = "sde:oracle11g";
            string sPassword = string.Format("{0}@{1}", userPass, serviceName);

            Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
            System.Object obj = Activator.CreateInstance(t);
            IWorkspaceFactory2 oWorkspaceFactory = obj as IWorkspaceFactory2;

            IPropertySet oPropertySet = new PropertySetClass();
            oPropertySet.SetProperty("SERVER", sSERVER);
            oPropertySet.SetProperty("DATABASE", "");
            oPropertySet.SetProperty("INSTANCE", sInstance);
            oPropertySet.SetProperty("USER", userName);
            oPropertySet.SetProperty("PASSWORD", sPassword);

            if (!string.IsNullOrEmpty(versionName))
                oPropertySet.SetProperty("VERSION", "SDE." + versionName);

            IWorkspace worckSpace = oWorkspaceFactory.Open(oPropertySet, 0);
            IEnumDatasetName dsNames = worckSpace.get_DatasetNames(esriDatasetType.esriDTAny);
            return worckSpace;
        }
3
  • 2
    Have you tried featureCursor.UpdateFeature() (and featureCursor.Flush()) instead of feature.Store() – Berend Aug 11 '20 at 15:03
  • 1
    Yes i do but it returns "Objects in this class cannot be updated outside an edit session" exception at var featureCursor = featureClass.Update(filter, false); row – Mahdi Ahmadi Aug 12 '20 at 3:41
  • 1
    This project was a Asp.Net Webforms application. It works well but the issue comes out when i upgraded project to a Asp.Net MVC application – Mahdi Ahmadi Aug 12 '20 at 3:43
1

That was from license binding. For editing you need to bind extensions as

    esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork,
    esriLicenseExtensionCode.esriLicenseExtensionCodeDataInteroperability

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.