Every once in a while the question comes up (which it did yesterday) on how one can implement upload-only tables in SQL Mobile - Basically it's the classic scenario of where the mobile device is used to capture activity for the day that will be uploaded to a central table on the server at the end of the day.
The way I've found that works well is to use RDA…
To make the table "upload only", do the Pull operation using a SQL statement that returns 0 records from the table you'll be uploading to. I usually use a condition like "where 1 = 0". By doing this, the table structure and indexes are created in the SQL Mobile database with no records.
With tracking enabled, the SQL Mobile database will automatically track all of the newly added records which can be sent back to the server at end of day by doing a regular Push.
Here's some sample code for creating an upload-only table.
private void CreateUploadOnlyTable()
{
const string localConnectionString =
@"Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source = \Sales.sdf";
const string serverConnectionString =
@"Provider=sqloledb; Data Source=TheDbServer;Initial Catalog=PointOfSale;
User Id=username;Password=<password>";
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess();
rda.LocalConnectionString = localConnectionString ;
rda.InternetUrl = @"http://theserver.com/SqlServerCE/sqlcesa30.dll";
// set other relevent connection propertys on rda
// Retrieve table structure and indexes but get not data
// Local SalesForToday table will track added records that can later be Push'ed
rda.Pull("SalesForToday", "select * from SalesHistory where 1 = 0",
serverConnectionString, RdaTrackOption.TrackingOnWithIndexes, "SalesForToday_Error");
}
Posted
Aug 10 2006, 09:14 AM
by
jim-wilson