Error Syncing Replica to Hosted Feature Layer

355
2
Jump to solution
08-07-2019 01:39 PM
MonikaLucas
New Contributor III

Hello,

I am using ArcGIS Runtime for .NET 100.5, and attempting to sync a .geodatabase replica to a hosted feature layer in ArcGIS Online. I am getting an error that states 'unable to synchronize replica'. When I look at the error details,  the message is 'Importing delta data changes failed'. 

To create the hosted feature layer, I created a Map in ArcGIS Pro with 30 point, line and polygon feature layers, and then used the tools to Share the map to an ArcGIS Online organizational account. I set the web map to be 'offline enabled', and I also enabled the 'Sync' option on the Hosted Feature Layer.

I was able to create the offline .geodatabase file with just a few lines of code thanks to the sample code provided by ESRI (see below), and I also used sample code to attempt to sync the replica (see below). I'm not sure how to troubleshoot this issue as there is little information provided in the error message. Has anyone else had a problem with this particular error, or have suggestions as to how to track more info about the error down?

Thanks!

Jen

Creating the replica

SpatialReference sp = new SpatialReference(3857); //Web mercator wkid

// Get the extent of the current map

//Envelope extent = mainMap.InitialViewpoint.TargetGeometry.Extent as Envelope;
Envelope extent = new Envelope(-9972280.458, 6146072.133, -9907308.984, 6193615.965, sp);

// Create a task for generating a geodatabase (GeodatabaseSyncTask).
_gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(_featureServiceUri);

// Get the default parameters for the generate geodatabase task.
GenerateGeodatabaseParameters generateParams = await _gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent);

// Create a generate geodatabase job.
GenerateGeodatabaseJob generateGdbJob = _gdbSyncTask.GenerateGeodatabase(generateParams, _gdbPath);

// Start the job.
generateGdbJob.Start();

// Get the result of the job.
_resultGdb = await generateGdbJob.GetResultAsync();

Syncing the replica with the server

Geodatabase resultGdb = await Esri.ArcGISRuntime.Data.Geodatabase.OpenAsync(_gdbPath);

// Create parameters for the sync task.
SyncGeodatabaseParameters parameters = new SyncGeodatabaseParameters()
{
     GeodatabaseSyncDirection = SyncDirection.Bidirectional,
     RollbackOnFailure = false
};

parameters.LayerOptions.Clear();

// Get the layer ID for each feature table in the geodatabase, then add to the sync job.
foreach (GeodatabaseFeatureTable table in resultGdb.GeodatabaseFeatureTables)
{

     // Get the ID for the layer.
     long id = table.ServiceLayerId;

     // Create the SyncLayerOption.
     SyncLayerOption option = new SyncLayerOption(id);

     // Add the option.
     parameters.LayerOptions.Add(option);
}

// Create job.
SyncGeodatabaseJob job = _gdbSyncTask.SyncGeodatabase(parameters, resultGdb);

job.Start();

// Wait for the result.
await job.GetResultAsync();

// Do the remainder of the work.
HandleSyncCompleted(job);

Reply
0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Regular Contributor

Just a guess but it might be that you are calling both job.Start() and job.GetResultsAsync() which is causing two different threads to try and sync the deltas at the same time.

If you are using GetResultsAsync approach you do not need to call job.Start().  GetResultsAsync simplifies processing of the job by wrapping everything in an async operation for you so you don't need to monitor the job.  If you do use job.Start() then you actually need to add your own job.ProgressChanged handler and handle the job completion in the event handler.  I don't know if the API has anything internally to check if a job object has kicked off a job so that it does not fire the same job request twice

View solution in original post

2 Replies
JoeHershman
MVP Regular Contributor

Just a guess but it might be that you are calling both job.Start() and job.GetResultsAsync() which is causing two different threads to try and sync the deltas at the same time.

If you are using GetResultsAsync approach you do not need to call job.Start().  GetResultsAsync simplifies processing of the job by wrapping everything in an async operation for you so you don't need to monitor the job.  If you do use job.Start() then you actually need to add your own job.ProgressChanged handler and handle the job completion in the event handler.  I don't know if the API has anything internally to check if a job object has kicked off a job so that it does not fire the same job request twice

View solution in original post

MonikaLucas
New Contributor III

Hi Joe,

Thanks for your help on this. I ended up creating a new prototype project to narrow down the code as I could not get the sync to work even with removing one or the other calls in my application. In my prototype, I used Job.Start() while monitoring the job and removed Job.GetResultAsync(). The prototype project worked fine. I appreciate your help in understanding these two approaches.

Thanks again!

Jen 

Reply
0 Kudos