Geodatabase transactions

View inAndroidFormsUWPWPFWinUIiOSView 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.GeodatabaseTransactions.GeodatabaseTransactions"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="200" />
        </Grid.RowDefinitions>
        <esriUI:MapView x:Name="MyMapView" Grid.Row="0" />
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="35" />
                <RowDefinition Height="35" />
                <RowDefinition Height="35" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition Width="30" />
                <ColumnDefinition Width="70" />
            </Grid.ColumnDefinitions>
            <Button x:Name="StartEditingButton"
                    Grid.Row="0"
                    Grid.Column="0"
                    Margin="2,0"
                    Clicked="BeginTransaction"
                    IsEnabled="False"
                    MinimumHeightRequest="35"
                    MinimumWidthRequest="100"
                    Text="Start Edit" />
            <Button x:Name="StopEditingButton"
                    Grid.Row="1"
                    Grid.Column="0"
                    Margin="2,0"
                    Clicked="StopEditTransaction"
                    IsEnabled="False"
                    MinimumHeightRequest="35"
                    MinimumWidthRequest="100"
                    Text="Stop Edit" />
            <Button x:Name="AddBirdButton"
                    Grid.Row="0"
                    Grid.Column="1"
                    Margin="2,0"
                    Clicked="AddNewFeature"
                    IsEnabled="False"
                    MinimumHeightRequest="35"
                    MinimumWidthRequest="80"
                    Text="Add Bird" />
            <Button x:Name="AddMarineButton"
                    Grid.Row="1"
                    Grid.Column="1"
                    Margin="2,0"
                    Clicked="AddNewFeature"
                    IsEnabled="False"
                    MinimumHeightRequest="35"
                    MinimumWidthRequest="100"
                    Text="Add Marine" />
            <Button x:Name="SyncEditsButton"
                    Grid.Row="0"
                    Grid.Column="3"
                    Margin="2,0"
                    Clicked="SynchronizeEdits"
                    IsEnabled="False"
                    MinimumHeightRequest="35"
                    MinimumWidthRequest="50"
                    Text="Sync" />
            <StackLayout Grid.Row="2"
                         Grid.ColumnSpan="4"
                         Orientation="Horizontal">
                <Label Margin="3"
                       FontSize="Small"
                       Text="Require a transaction for edits"
                       VerticalOptions="Center" />
                <Switch x:Name="RequireTransactionCheckBox"
                        Margin="3"
                        IsToggled="True"
                        Toggled="RequireTransactionChanged"
                        VerticalOptions="Center" />
            </StackLayout>
            <Label x:Name="MessageTextBlock"
                   Grid.Row="3"
                   Grid.ColumnSpan="4"
                   Margin="5"
                   FontSize="Micro"
                   HorizontalOptions="FillAndExpand"
                   LineBreakMode="CharacterWrap"
                   Text="Generating local geodatabase ..."
                   VerticalOptions="FillAndExpand">
                <Label.TextColor>
                    <OnPlatform x:TypeArguments="Color">
                        <OnPlatform.Platforms>
                            <On Platform="iOS" Value="Blue" />
                            <On Platform="Android" Value="White" />
                            <On Platform="UWP" Value="Blue" />
                        </OnPlatform.Platforms>
                    </OnPlatform>
                </Label.TextColor>
            </Label>
            <ActivityIndicator x:Name="LoadingProgressBar"
                               Grid.Row="1"
                               Grid.Column="3"
                               HorizontalOptions="FillAndExpand"
                               IsRunning="True" />
        </Grid>
    </Grid>
</ContentPage>

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