Sync Framework Tips and Troubleshooting
This article collects tips on using Sync Framework, and provides help troubleshooting problems you might encounter on your path to synchronization.
An article like this is an eternal work in progress, so please add your own tips and troubleshooting advice if you don't find it here!
The Sync Framework Developer Discussions forum is another excellent place to ask questions and find answers.
General Troubleshooting
Managed Application Throws System.Runtime.InteropServices.COMException (0x80040154)
Problem: A managed synchronization application throws System.Runtime.InteropServices.COMException with the following error message: "Retrieving the COM class factory for component with CLSID {565AEDBF-3108-4405-AF1F-9C2C25925DAE} failed due to the following error: 80040154."
Solution: This occurs when the processor type for which an application is built does not match the processor type for which Sync Framework is installed. For example, your application targets the x86 processor and you have the x64 version of Sync Framework installed. In Visual Studio, change the Platform Target in the Build pane of your project properties to match the Sync Framework processor type.
Solution: This also occurs when an unmanaged synchronization component, such as Synchronization.dll, is missing from the installation. This can occur when Sync Framework has been uninstalled or when installation was not completed successfully. Reinstall Sync Framework to fix this.When Sync Framework tracing runs for a long time, the tracing output file gets very large, and there isn't any integrated support for rolling over to a new tracing file or for clearing out old traces to keep the file size manageable. This blog post about Rolling over TextWriterTraceListener logs does a nice job of showing you how to override the System.Diagnostics.TextWriterTraceListener class to start logging to a new file on a pre-specified interval. For more information on tracing Sync Framework, see How to: Trace the Synchronization Process.
Side-by-side installation of 32-bit and 64-bit versions of Sync Framework 2.1 SDK is not supported. For example, if you try to install 32-bit version of Sync Framework 2.1 SDK on a computer that already has 64-bit version on it, you will receive an error message: "Unable to install because a newer version of this product is already installed". It is not possible have full 32-bit Sync Framework 2.1 SDK installed side-by-side with the 64-bit SDK; therefore you will have to install one version of SDK (64-bit) completely and only selected components of other version (32-bit) of SDK. You can install the selected components of the SDK from Sync Framework 2.1 Redistributable Packages page and full SDK package from Sync Framework SDK download page .
Database Synchronization
Use snapshot initialization to create and initialize multiple SQL Server Compact databases in your synchronization community. Snapshot initialization offers much faster performance for setting up multiple SQL Server Compact databases than provisioning each one individually. And the API is simple, too! Here's an article that tell you how to do this: http://msdn.microsoft.com/en-us/library/gg294193(v=SQL.110).aspx.
Use backup and restore (with post-restore fixup) to create and initialize multiple large SQL Server databases in your synchronization community. If you are setting up a synchronization community that contains copies of a large SQL Server database, performance will be better if you use backup and restore to create the database copies instead of an initial synchronization. Here's an article that tells you how to do this: http://msdn.microsoft.com/en-us/library/ee617375(v=SQL.110).aspx.
Don't use TRUNCATE TABLE to modify a table that is synchronized. This is because, while TRUNCATE TABLE is in effect a DELETE statement, it does not activate the trigger used to update the change tracking metadata, so the deletion is invisible to Sync Framework and will not be sent to other replicas.
To find a list of the scopes that are currently provisioned in a database, query the scope_info table. The scope_info table contains information about each scope, including the scope name.
When a table in a SQL Server Compact database is initialized through synchronization, the seed and increment of its identity columns are always set to 0 and 1, respectively, regardless of how they are set on the server database. If you need to insert rows locally in the client database you must first set the identity seed and increment to appropriate values or manually specify the identity column value, otherwise new rows will have duplicate identity values and row insertion will fail. The identity seed and increment can be set with the following query, which sets the seed value to 10 and the increment to 1:
ALTER TABLE ExampleTable ALTER COLUMN idCol IDENTITY(10,1)
File Synchronization
A large metadata file can take a long time to send to each client during synchronization. The solution to this is to store the metadata file on each client, rather than just on the server. To do this, specify a local client path for the metadata file when the FileSyncProvider object is created on the client, such as in the following code example:
FileSyncProvider myClientProvider = new FileSyncProvider("c:\\syncfolder", myFilter, myOptions, "c:\\syncmetadata", null, null);
There is no theoretical upper limit for the number or size of files that can be synchronized, but in practice replicas that contain more than 500,000 files can lead to performance degradation, particularly when detecting changes. To fix this, break folders into separate replicas and synchronize them separately.
A bug in Sync Framework 2.1 corrupts the metadata file when synchronization is canceled during the change detection phase, which leads to extremely long synchronization times in subsequent sessions. One workaround is to explicitly call FileSyncProvider.DetectChanges and don't allow synchronization to be canceled during this phase. Another workaround is to always save a backup copy of the metadata file and, when synchronization is canceled, roll back to the backup metadata for the next synchronization.