Geodatabase transactions

View inMAUIUWPWPFWinUIView on GitHub

Use transactions to manage how changes are committed to a geodatabase.

Image of geodatabase transactions

Use case

Transactions allow you to control how changes are added to a database. This is useful to ensure that when multiple changes are made to a database, they all succeed or fail at once. For example, you could have a business rule that both parent/guardian and student must be added to a database used for calculating school bus routes. You can use transactions to avoid breaking the business rule if you lose power while between the steps of adding the student and parent/guardian.

How to use the sample

When the sample loads, a feature service is taken offline as a geodatabase. When the geodatabase is ready, you can add multiple types of features. To apply edits directly, uncheck the 'Require a transaction for edits' checkbox. When using transactions, use the buttons to start editing and stop editing. When you stop editing, you can choose to commit the changes or roll them back. At any point, you can synchronize the local geodatabase with the feature service.

How it works

  1. Take the feature service offline as a geodatabase and display the local tables from the geodatabase in feature layers.
  2. If the checkbox is checked, begin the transaction on the geodatabase.
  3. Add one or more features.
  4. When ready, either commit the transaction to the geodatabase or roll back the transaction.
  5. Use a geodatabase sync task to sync changes to the local geodatabase with the feature service.

Relevant API

  • Geodatabase
  • Geodatabase.BeginTransaction
  • Geodatabase.CommitTransaction
  • Geodatabase.IsInTransaction
  • Geodatabase.RollbackTransaction

About the data

The sample uses a publicly-editable, sync-enabled feature service demonstrating a schema for recording wildlife sightings.

Tags

commit, database, geodatabase, transact, transactions

Sample Code

GeodatabaseTransactions.xamlGeodatabaseTransactions.xamlGeodatabaseTransactions.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<UserControl
    x:Class="ArcGIS.UWP.Samples.GeodatabaseTransactions.GeodatabaseTransactions"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <UserControl.Resources>
        <Style TargetType="Button">
            <Setter Property="HorizontalAlignment" Value="Stretch" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">

            <StackPanel Orientation="Vertical">
                <Grid Margin="5,10,0,5"
                      ColumnSpacing="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Button x:Name="StartEditingButton"
                            Grid.Column="0"
                            Content="Start editing"
                            IsEnabled="False"
                            Click="BeginTransaction" />
                    <Button x:Name="StopEditingButton"
                            Grid.Column="1"
                            Content="Stop editing"
                            IsEnabled="False"
                            Click="StopEditTransaction" />
                    <Button x:Name="SyncEditsButton"
                            Grid.Column="2"
                            Content="Sync"
                            IsEnabled="True"
                            Click="SynchronizeEdits" />
                </Grid>
                <Grid Margin="5,0,0,0"
                      ColumnSpacing="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Button x:Name="AddBirdButton"
                            Grid.Column="0"
                            Content="Add bird"
                            IsEnabled="False"
                            Click="AddNewFeature" />
                    <Button x:Name="AddMarineButton"
                            Grid.Column="1"
                            Content="Add marine"
                            IsEnabled="False"
                            Click="AddNewFeature" />
                </Grid>
                <CheckBox x:Name="RequireTransactionCheckBox"
                          Content="Require a transaction for edits"
                          Margin="8,3"
                          IsChecked="True"
                          Click="RequireTransactionChanged" />
                <TextBlock x:Name="MessageTextBlock"
                           Text="Generating local geodatabase ..."
                           Foreground="RoyalBlue"
                           Height="40"
                           Margin="5"
                           TextWrapping="Wrap" />
                <ProgressBar x:Name="LoadingProgressBar"
                             Height="10"
                             Margin="3"
                             IsIndeterminate="True"
                             Opacity="0.5" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.