Restore client database without re-syncing all data RRS feed

  • Question

  • I've got an application using Sync Framework 2.1 to sync multiple client PCs (SQL Express) to a central SQL/Server database. The database is quite large and the Internet connection relatively slow so I'd like to include a compressed backup as part of the installation package and then restore it when the application is installed and have the sync continue on only updating new records from when the backup was taken.

    At the moment if I provision the server and client, update the local database and take a backup when it's restored on the clients it attempts to download all records. It appears from the documentation this code is for the server-side but I've tried running this on the client after the restore without success:

    serverConn = New SqlConnection(My.Settings.ConnectionString)
    Dim databaseRestore As New SqlSyncStoreRestore(serverConn)

    I was wondering the correct way to handle this situation?

    Tuesday, August 14, 2012 4:19 AM


All replies

  • performpostrestorefixup should be done on the database that was restored.
    Tuesday, August 14, 2012 5:11 AM
  • Thanks for the response JuneT but as per the code snippet above I've tried calling PerformPostRestoreFixup. It runs without any errors but I still get the same result of it attempting to sync all records.
    Tuesday, August 14, 2012 6:13 AM
  • is serverconn pointing to the restored database?

    are you sure you are not re-provisioning your client?

    Tuesday, August 14, 2012 10:37 AM
  • Hi June, yes it's pointing at the same restored database, I restore using a connection to the database using the same connection string minus the initial catalog because it doesn't exist at that point and the restore command is executed using an ExecuteNonQuery statement. However I close the connection after the restore before executing the PerformPostRestoreFixup, the SQL statement I use for the restore is:


    The part {APPLICATIONDIR} is something I replace in code with the application path at runtime. I'm definitely not calling a re-provision of the client during the process. The database is restored OK and further code using the same connection string retrieves all the data I'd expect.

    Tuesday, August 14, 2012 11:33 AM
  • can you enable sync fx tracing and post the trace...

    • Marked as answer by PeterJ123 Wednesday, August 15, 2012 1:56 AM
    Tuesday, August 14, 2012 11:49 AM
  • Thanks June will do, it's quite late here but will take a look in the morning and post pack results.
    Tuesday, August 14, 2012 11:52 AM
  • just a couple more question, when you provision the client, does it contain data already? after you provision it, do you sync with the server before you do a backup?

    Tuesday, August 14, 2012 12:11 PM
  • Hi June, thanks for the hint on enabling tracing, I wasn't aware of that and it helped solve my problem. The underlying problem was that when provisioning the databases I'd used a query to retrieve the table names without considering the update order so I had a stack of foreign key constraint errors in the sync log. I've sinced added a table that contains the list of table names I want to sync along with a sequence number so that they are always provisioned in the right order to avoid constraint violations.

    Before doing that my sync log was too long to read over fully but I imagine when I was getting zero records updated and thought the database had been synced it had just not updated any records because of the errors so the clients would try to start again. Anyway it's all working now and I've added some additional error detection to pick up any future problems like that so thanks for your assistance.

    Wednesday, August 15, 2012 1:56 AM