Mobile Cache Not Saving Edits

1188
5
07-22-2011 11:55 AM
KirmanieRavariere
New Contributor
I used the Create Mobile Map geoprocessing tool in ArcGIS 10's toolbox to generate a mobile map from an MXD. The MXD has one layer which featureclass is:

1) in a geodatabase
2) registered as versioned and
3) has a globalid

all the requirements for generating a mobile cache JUST to take advantage of ArcGIS Mobile's mapping capabilities.

I then took the MapSchema.bin file and dropped it in a folder on my Windows Mobile device. I wrote a small test Smart Device application in Visual Studio that has this code:

            using (MobileCache cache = new MobileCache(mobileCachePath))
            {
                cache.Open();

                FeatureLayer layer = cache.Layers[0] as FeatureLayer;
                FeatureDataTable table = layer.GetDataTable();

                FeatureDataRow row = table.NewRow();
                row["area_id"] = 1;
                table.Rows.Add(row);

                int recordsAffected = table.SaveInFeatureLayer();
                //recordsAffected is always 0


                using (FeatureDataReader reader = layer.GetDataReader(null, null))
                    while (reader.Read())
                    {
                        //never reaches here
                    }

                table = layer.GetDataTable(new QueryFilter("area_id=" + 1));
                int foundRows = table.Rows.Count;
                //foundRows is always 0

                cache.Close();
            }

As you can tell from the comments in the code, I can't find my new records anywhere. I open the MobileCache.db file in a Sqlite browser and the tables are empty. I read that I could use the MobileCache in a headless fashion, is this not what ESRI meant? Can anyone fill me in on what I'm missing?
0 Kudos
5 Replies
MelindaFrost
Occasional Contributor
In your code snippet I don't see you setting the geometry- not sure if that is it.
You can also check if getting any errors on save:

//create datareader
FeatureDataTable featDataTable = featureLayer.GetDataTable(new QueryFilter());               
// creates a new row
DataRow newFeatDataRow = featDataTable.NewRow();                
                
newFeatDataRow[featDataTable.GeometryColumnIndex] = newpolyline;
//sets the new geometry to the feature layer data table
featDataTable.Rows.Add(newFeatDataRow);

                //now save edits
                int result = featDataTable.SaveInFeatureLayer();
                DataRow[] errors = featDataTable.GetErrors();
                for (int i = 0; i < errors.Length; i++)
                {
                     if ( errors.HasErrors ) {
                          // get the array of columns in error.
                          DataColumn [ ] colArr = errors.GetColumnsInError( );
                         for ( int j = 0; j < colArr.Length; j++ ) {
                             // insert code to fix errors on each column.
                            MessageBox.Show("Error with creating new flight column " + (colArr.ColumnName) );
                          }
                     }
                }
0 Kudos
FabianHeredia
New Contributor II
if you have VS2008 and 2010 installed on your PC may experience problems when you debbug, issues are not displayed and can corrupt the cache
0 Kudos
Hang_KwaiPun
New Contributor
Hi guys,

it shouldn't be a matter whether you specify the geometry for the new row, but there are some extra steps you might want to take:

1. Use the "using" keyword for the FeatureDataTable,  (but you don't need one for MobileCache)
2. After a new Row is created, call row.BeginEdit() to start and row.EndEdits() to close the editing session.

A work around for the issue is to create a new record using a FeatureDataReader instead of a FeatureDataTable. again it will be good if you use the using keyword for the FeatureDataReader.

If still you cannt save locally you might want to check if it's something happening with the layer/cahe itself. You might want to check if your cache is valid after opening it.

and for more checking (that's just my usual practice), you might want to check if your FeatureDataTable has the correct number of rows before you add any new row. since the table itself might have problems.

Please let us know if that helps!

Tif
0 Kudos
FabianHeredia
New Contributor II
when I cache satellite imagery has generated additional files if I open the cache in the traditional way I get the error that the file is invalid or corrupt
0 Kudos
ThiagoHumberto_Geraldi
New Contributor II
I'm working with 9.2 Mobile migration project for 10. To resolve this issue you need to add the command reader.Close() soon after the end of your code.
Sample:

                using (FeatureDataReader reader = layer.GetDataReader(null, null))
                    while (reader.Read())
                    {
                      //editions
                    }
if (reader!= null && !reader.IsClosed)
                    reader.Close();

Att
Thiago Geraldi
0 Kudos