Select to view content in your preferred language

Offline Sync geodatabase: empty table / feature layer results

571
4
Jump to solution
11-28-2023 02:30 PM
Labels (2)
MoyerSolutions
New Contributor III

Hello! I need an offline syncable geodatabase. I am trying to read fields from a geodatabase, but the results are empty.  None of the fields load.

2023-11-28 14_52_31-Window.png

The table has fields, I'd expect to see these headers:

2023-11-28 15_13_38-Window.png

My code is effectively the same as the sample from the ArcGIS.WinUI.Samples.GeodatabaseTransactions

 

 

private async Task GetLocalGeodatabase()
{
    // Get the path to the local geodatabase for this platform (temp directory, for example).
    string localGeodatabasePath = GetGdbPath();

    try
    {
        // See if the geodatabase file is already present.
        if (File.Exists(localGeodatabasePath))
        {
            // If the geodatabase is already available, open it, hide the progress control, and update the message.
            _localGeodatabase = await Geodatabase.OpenAsync(localGeodatabasePath);
            LoadingProgressBar.Visibility = Visibility.Collapsed;
            MessageTextBlock.Text = "Using local geodatabase from '" + _localGeodatabase.Path + "'";
        }
        else
        {
            // Create a new GeodatabaseSyncTask with the uri of the feature server to pull from.
            Uri uri = new Uri(SyncServiceUrl);
            GeodatabaseSyncTask gdbTask = await GeodatabaseSyncTask.CreateAsync(uri);

            // Create parameters for the task: layers and extent to include, out spatial reference, and sync model.
            GenerateGeodatabaseParameters gdbParams = await gdbTask.CreateDefaultGenerateGeodatabaseParametersAsync(_extent);
            gdbParams.OutSpatialReference = MyMapView.SpatialReference;
            gdbParams.SyncModel = SyncModel.Layer;
            gdbParams.LayerOptions.Clear();
            gdbParams.LayerOptions.Add(new GenerateLayerOption(0));
            gdbParams.LayerOptions.Add(new GenerateLayerOption(1));

            // Create a geodatabase job that generates the geodatabase.
            GenerateGeodatabaseJob generateGdbJob = gdbTask.GenerateGeodatabase(gdbParams, localGeodatabasePath);

            // Handle the job changed event and check the status of the job; store the geodatabase when it's ready.
            generateGdbJob.StatusChanged += (s, e) =>
            {
                // See if the job succeeded.
                if (generateGdbJob.Status == JobStatus.Succeeded)
                {
                    DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
                    {
                        // Hide the progress control and update the message.
                        LoadingProgressBar.Visibility = Visibility.Collapsed;
                        MessageTextBlock.Text = "Created local geodatabase";
                    });
                }
                else if (generateGdbJob.Status == JobStatus.Failed)
                {
                    DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
                    {
                        // Hide the progress control and report the exception.
                        LoadingProgressBar.Visibility = Visibility.Collapsed;
                        MessageTextBlock.Text = "Unable to create local geodatabase: " + generateGdbJob.Error.Message;
                    });
                }
            };

            // Start the generate geodatabase job.
            _localGeodatabase = await generateGdbJob.GetResultAsync();
        }
    }
    catch (Exception ex)
    {
        // Show a message for the exception encountered.
        DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
        {
            _ = new MessageDialog2("Unable to create offline database: " + ex.Message).ShowAsync();
        });
    }
}

 

 

Strangely enough it seems to loaded the Domains , so I know its downloaded the correct table:

2023-11-28 15_10_57-Window.png

 

Editing is enabled in the service, and all users should be able to view features:

2023-11-28 15_29_06-Window.png

 

0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Regular Contributor

Are you calling LoadAsync ?

You need to explicitly Load tables/layers, etc

Thanks,
-Joe

View solution in original post

4 Replies
MoyerSolutions
New Contributor III

 

So I have tried to make a smaller test case using ServiceFeatureTable or through ServiceGeodatabase:. Results are same: empty table

public static async Task ServiceGeodatabase() {
    var serviceGeodatabase = new ServiceGeodatabase(new Uri(featureServiceUri));
    await serviceGeodatabase.LoadAsync();

    ServiceFeatureTable table = serviceGeodatabase.GetTable(0);
    _ = table.Fields; //breakpoint here, why this is empty?
}

 

-or-

 

public static async Task GetServiceTable() {
    ServiceFeatureTable table = new(new Uri(featureServiceUri));
    var layer = new FeatureLayer(table);
    _ = table.Fields; //breakpoint here, why this is empty?
}

 

 

 

 

 

0 Kudos
JoeHershman
MVP Regular Contributor

Are you calling LoadAsync ?

You need to explicitly Load tables/layers, etc

Thanks,
-Joe
MoyerSolutions
New Contributor III

That was it. Thank you!

0 Kudos
MoyerSolutions
New Contributor III

Follow up question, not sure if I should make a new topic, but now I am trying to read the fields / attributes from the table after it has been loaded. I keep getting "null" as a response. There is data in the table. Is there something else I need to call to load the actual values themselves?

edit: solved 

 

 

0 Kudos