Select to view content in your preferred language

Unable to Sync Mobile Geodatabase to Feature Server Using C# ESRI SDK

257
1
06-01-2024 10:13 AM
rfrith3142
New Contributor

Trying to sync a local mobile geodatabase to a feature server using ESRI C# SDK and WPF. The schemas match, there are no permission problems, the network is operational. Here's the code. Nothing revealed in the inner exceptions except vague messages that offer no insights. What's wrong with this code?

var LocalGeodatabasePath = "...";
var FeatureServiceUrl = "...";
 
try
            {
                // Load the local geodatabase
                Geodatabase localGeodatabase = await Geodatabase.OpenAsync(LocalGeodatabasePath);
                Console.WriteLine("Local geodatabase loaded.");
 
                // Create the SyncGeodatabaseTask
                var syncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(FeatureServiceUrl));
                Console.WriteLine("SyncGeodatabaseTask created.");
 
                // Create the SyncGeodatabaseParameters
                SyncGeodatabaseParameters syncParams = await syncTask.CreateDefaultSyncGeodatabaseParametersAsync(localGeodatabase);
                // Check layers in the sync parameters
                foreach (var layerOption in syncParams.LayerOptions)
                {
                    Console.WriteLine($"LayerOption for layer {layerOption.LayerId}");
                }
                Console.WriteLine("SyncGeodatabaseParameters created.");
 
                // Sync direction: Push local changes to the server
                syncParams.GeodatabaseSyncDirection = SyncDirection.Bidirectional;
 
                // Optionally, you can adjust other sync parameters here
 
                // Create a job to synchronize the geodatabase
                SyncGeodatabaseJob syncJob = syncTask.SyncGeodatabase(syncParams, localGeodatabase);
 
                // Handle job status changes
                syncJob.JobChanged += (s, e) =>
                {
                    Console.WriteLine($"Job status changed: {syncJob.Status}");
                    if (syncJob.Status == JobStatus.Succeeded)
                    {
                        Console.WriteLine("Synchronization succeeded.");
                    }
                    else if (syncJob.Status == JobStatus.Failed)
                    {
                        Console.WriteLine($"Synchronization failed: {syncJob.Error.Message}");
                    }
                };
 
                // Start the job
                syncJob.Start();
 
                // Wait for the job to complete
                var syncResult = await syncJob.GetResultAsync();
 
                // Check for errors
                if (syncJob.Status == JobStatus.Succeeded)
                {
                    // Retrieve and store the replica ID
                    var replicaInfo = syncResult;
                    Console.WriteLine($"Synchronization complete. Replica ID: {replicaInfo.ToString()}");
                }
                else
                {
                    Console.WriteLine($"Synchronization failed: {syncJob.Error.Message}");
                }
            }
            catch (ArcGISWebException ex)
            {
                Console.WriteLine($"ArcGISWebException: {ex.Message}");
                if (ex.InnerException != null)
                {
                    Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message}");
                if (ex.InnerException != null)
                {
                    Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
                }
            }
 
Job status changed: Started
Job status changed: Started
Job status changed: Started
Job status changed: Started
Job status changed: Started
Job status changed: Failed
Synchronization failed: Unable to complete operation.
Exception thrown: 'Esri.ArcGISRuntime.Http.ArcGISWebException' in mscorlib.dll
ArcGISWebException: Unable to complete operation.
 
Using:
ESRI.ArcGIS.Client
run-time version: 4.0.30319
version: 3.0.0.146
 
Feature service hosted on AGOL 10.91
 
Remote and local schemas match.
 

0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor

I do not see anything wrong with your code that could've led to this error. Just a suggestion (but likely not relevant to the error you're seeing) since you are awaiting the result of syncJob.GetResultAsync() already in a try-catch. There is no need to call syncJob.Start() or handle success/fail in JobChanged.

Based on the API name, I think you are using an older version of ArcGIS Maps SDK for .NET. One thing I would like to suggest (if you're able) is try the same request with latest 200.4. The equivalent event for JobChanged is StatusChanged. There is also a MessageAdded that could provide some insight at what stage this error happens (if it still happens). 

There could be a number of things that could result to this generic server error. Are you able to inspect ArcGISWebException.Details property? According to this doc, one possibility is the replica GUID no longer exists on server. If you have access to the ArcGIS Server Logs, it may give more information on the GP Server error.

You can also see if you are hitting these support issues:

https://support.esri.com/en-us/knowledge-base/error-code-400-description-unable-to-complete-operatio...

 https://support.esri.com/en-us/knowledge-base/problem-unable-to-sync-services-in-arcgis-server-00002...

Another case that I've seen in my sync testing, it's possible for sync to fail to acquire the necessary lock to apply delta changes or have synchronization conflicts that need to be resolved.

0 Kudos