Tuesday, December 8, 2009

ADO.Net Synchronization

The ADO.Net Sync Framework has some very nice capabilities for synchronizing a variety of data sources.  It even has capabilities for synchronizing files or if you were ambitious enough, you could develop a custom data source provider to work with sync services.

The design of the application I’m working on is based on a local SQL Server Compact Edition database on the client machine and a more centralized SQL Server Express database that aggregates data from each client machine.  Sync services will do the job of synchronizing each SQL Server CE database with the SQL Server Express database, but I was wondering if it would also do the job of synching the data in the DataSet with SQL Server CE.  It seems to be a logical capability for it to provide since it is able to synchronize a number of different types of data sources and a DataSet schema looks just like the database it is derived from.

I found out that ADO.Net synchronization will not provide that capability; however, I found another way of accomplishing that objective that’s very nice and very easy to implement.  The tricky part about database updates comes into play when you have related tables with foreign key constraints and they have to be updated in the proper sequence to avoid a foreign key violation.  In the original design of my application, I had some custom ADO.Net code that did that, but I wanted to find a way to simplify and standardize that code as much as possible.  That was one of the key things I was hoping Sync Services would do for me.

The technique I wound up using is a TableAdapterManager.  The TAM is a relatively new capability and it does exactly what I was looking for synch services to do to synch the DataSet with the SQL CE database.  You create a TableAdapterManager to consist of one or more TableAdapters for all the tables in a relationship, and simply use the “UpdateAll” method on the TAM and it will update all of the related tables in the proper sequence to avoid foreign key constraint errors.  The TAM is a very nice capability!

Chuck

0 comments:

Post a Comment