Hi ArcGIS Pro SDK professionals,
I am trying to create a stand-alone CoreHost application. It's quite easy task if you are an experienced ArcObjects SDK developer.
I have a problem when I try to save edits to the Oracle SDE geodatabase. Feature.Store() method "inside" Geodatabase.ApplyEdits() throws an exception:
ArcGIS.Core.Data.GeodatabaseObjectClassException: Objects in this object class cannot be updated outside of an edit session. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80041354
at ArcGIS.Core.Internal.IRowIOP.Row_Store(IntPtr rowHandle)
at ArcGIS.Core.Data.GeodatabaseUtil.Store(IntPtr rowHandle)
--- End of inner exception stack trace ---
at ArcGIS.Core.Data.GeodatabaseUtil.Store(IntPtr rowHandle)
...
I have tried to save edits without ApplyEdits. Same result.
The feature class is a non-versioned SDE feature class (database table). It has lots of relationship classes (sub database tables).
If I edit data (using the same source code) of another feature class (without relationship classes), no exceptions are thrown. That's why I wonder if the CoreHost implementation does not support editing non-versioned feature class having relationship classes.
Do you have any idea what I am doing wrong? Or is there really above-mentioned restriction?
Jorma
Hi Jorma,
Would you be willing to share a code sample? There should not be any restrictions like you have described, although it's always possible that there is a bug in this area.
Thanks,
--Rich
Hello Rich,
Here is the simplified source code (ApplyEdits-version):
public override AMUStatus Execute(Dictionary<long, short> objectsTable)
{
AMUStatus status = AMUStatus.OK;string methodName = "Execute";
string inputData = String.Format("objectsTable.Count = {0}", objectsTable.Count);try
{
LogInfoMessage(methodName, String.Format("Calculate FR stand area data. {0}.", inputData));/* TEST-TEST */
LogDebugMessage(methodName, String.Format("Geodatabase: GetGeodatabaseType() = {0}, IsVersioningSupported = {1}.", this.Gdb.GetGeodatabaseType(), this.Gdb.IsVersioningSupported()));// Feature classes of the MVK_KUVIO and GEO_TIEVIIVA tables
using (FeatureClass standFeaClass = this.Gdb.OpenDataset<FeatureClass>(this.ObjectTableName))
using (FeatureClass roadLineFeaClass = this.Gdb.OpenDataset<FeatureClass>(c_roadLineTableName))
{
/* TEST-TEST */
LogDebugMessage(methodName, String.Format("FeatureClass: GetName() = {0}, GetRegistrationType() = {1}.", standFeaClass.GetName(), standFeaClass.GetRegistrationType()));long objId;
AMUStatus calcStatus = AMUStatus.OK;/* TEST-TEST. Edit FeatureClass without RelationshipClasses. */
LogDebugMessage(methodName, String.Format("FeatureClass: GetName() = {0}, GetRegistrationType() = {1}.", roadLineFeaClass.GetName(), roadLineFeaClass.GetRegistrationType()));
QueryFilter roadLineQF = new QueryFilter
{
WhereClause = "TIEVIIVA_ID IN (808473,808474,808475,808476,808477,808478)"
};using (RowCursor roadLineRowCursor = roadLineFeaClass.Search(roadLineQF, false))
{
this.Gdb.ApplyEdits(() =>
{
// Use try-catch block to avoid unhandled exception inside the edit action.
try
{
while (calcStatus == AMUStatus.OK && roadLineRowCursor.MoveNext())
{
using (Feature roadLineFea = (Feature)roadLineRowCursor.Current)
{
objId = roadLineFea.GetObjectID();
// Update PAIVITTAJA, PAIVITYS_AIKA columns
SetUpdateFieldsValues(roadLineFea);
// Store updates
roadLineFea.Store();
}
}
}
catch (Exception ex)
{
status = AMUStatus.GdbOperationFailed;
LogException(methodName, ex);
}
});
}
/* */// Go thru all MVK_KUVIO rows. Do not use recycling.
m_standQueryFilter.ObjectIDs = objectsTable.Keys.ToList();
using (RowCursor standRowCursor = standFeaClass.Search(m_standQueryFilter, false))
{
// Start editing in stand-alone mode. Lambda action is used here.
this.Gdb.ApplyEdits(() =>
{
// Use try-catch block to avoid unhandled exception inside the edit action.
try
{
while (calcStatus == AMUStatus.OK && standRowCursor.MoveNext())
{
using (Feature standFea = (Feature)standRowCursor.Current)
{
objId = standFea.GetObjectID();
/* TEST-TEST */
// Update PAIVITTAJA, PAIVITYS_AIKA columns
SetUpdateFieldsValues(standFea);
// Store updates
standFea.Store();
/* */
}
}}
catch (Exception ex)
{
status = AMUStatus.GdbOperationFailed;
LogException(methodName, ex);
}
});
}
}
}
catch (Exception ex)
{
status = AMUStatus.GdbOperationFailed;
LogException(methodName, ex);
}return status;
}
Here this.Gdb is the Geodatabase object, m_standQueryFilter is previously created QueryFilter object and SetUpdateFieldsValues() method which simply updates two column values of the current feature (row[fldName] = fldVal;).
The first ApplyEdits block is here to just testing editing the feature class without relationship classes. The exception is also thrown if this first ApplyEdits block is commented.
And here is the log file data:
[2019-06-13 09:03:15,771 INFO] FRStandAreaCalculator.Execute: Calculate FR stand area data. objectsTable.Count = 100.
[2019-06-13 09:03:17,278 DEBUG] FRStandAreaCalculator.Execute: Geodatabase: GetGeodatabaseType() = RemoteDatabase, IsVersioningSupported = True.
[2019-06-13 09:03:18,275 DEBUG] FRStandAreaCalculator.Execute: FeatureClass: GetName() = MVJ.MVK_KUVIO, GetRegistrationType() = Nonversioned.
[2019-06-13 09:03:18,281 DEBUG] FRStandAreaCalculator.Execute: FeatureClass: GetName() = MV.GEO_TIEVIIVA, GetRegistrationType() = Nonversioned.
[2019-06-13 09:03:32,294 FATAL] FRStandAreaCalculator.Execute: ArcGIS.Core.Data.GeodatabaseObjectClassException: Objects in this object class cannot be updated outside of an edit session. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80041354
at ArcGIS.Core.Internal.IRowIOP.Row_Store(IntPtr rowHandle)
at ArcGIS.Core.Data.GeodatabaseUtil.Store(IntPtr rowHandle)
--- End of inner exception stack trace ---
at ArcGIS.Core.Data.GeodatabaseUtil.Store(IntPtr rowHandle)
at Tieto.Forest.Aarni.AarniMassUpdate.FRStandAreaCalculator.<>c__DisplayClass10_3.<Execute>b__1() in D:\AarniDev\Src\Git\AarniMassUpdate\AarniMassUpdate\FRStandAreaCalculator.cs:line 240
BR. Jorma
Hi Jorma,
We've taken a look at your code, and from what we can see, everything looks fine.
One thing we noticed is that the two tables you are editing are non-versioned. How about the tables/feature classes that have relationship classes with MVK_KUVIO? You cannot edit both versioned and non-versioned tables in the same call to Geodatabase.ApplyEdits(). If editing MVK_KUVIO is triggering an update to a related table that is versioned, this could be the source of the error.
If this isn't the case, you may want to log this with technical support.
I hope this helps,
--Rich
Hi Rich,
Unfortunately, this does not help. All database tables in our enterprise geodatabase are registered as non-versioned. We do not have any versioned tables at all.
I have a few similar ArcObjects-based stand-alone applications and there are no issues when editing data of the same feature class.
BR. Jorma