Update scope definition after schema changes - Sql Compact RRS feed

  • Question

  • Hello

    I use MS Sync 2.1 to download some data from my server (SQL Express) to my client (SQL Compact).

    From time to time I need to change the tables included in sync scopes (add columns to my tables) and I do not want to drop the scope, recreate it and perform the sync again, I want to update the scope definition.

    For SQL Express, I have adapted the solution described jtabadero.wordpress.com/2011/04/13/modifying-sync-framework-scope-definition-part-3-workarounds-addingremoving-columns/ 

    For SQL Compact I use something like this: I create a local test database which includes my latest sghema updates and I provision the scope and I copy the scope config from it and update on my work database. Here is the code I run, where newConfigData represents the value I read from scope_config table from SQL Compact database.

    public void UpdateProvisionSchema(string connString, string scopeName, string newConfigData)
        _log.Verbose("UpdateProvisionSchema: " + scopeName);
            string query = string.Format("SELECT [scope_config_id] FROM [scope_info] WHERE [sync_scope_name]='{0}'", scopeName);
            Guid config_id = (Guid)SqlCompactManager.ExecuteScalar(connString, query);
            string updateCommand = string.Format("UPDATE scope_config SET [config_data]='{0}' WHERE [config_id] ='{1}'", newConfigData, config_id);
            SqlCompactManager.ExecuteCommand(connString, updateCommand);
        catch (Exception ex)
            _log.Error(ex, string.Format("Failed to upgrade schema for scope {0}", scopeName));
            throw new Exception(string.Format("Update of provisioned schema failed for scope: {0}", scopeName));
    Is there a better way to achieve this? I want to get rid of the new scope config string and I wonder if there is a way to read/get the scope from server database and update it local.

    Thanks in advance

    Thursday, July 10, 2014 7:06 AM

All replies

  • there is no direct way to update the scope_config using the API other than the provisioning part.

    you can get a scope definition using GetDescriptionForScope, but this will not include filters.

    if you call GetDescriptionForScope, you will find the the scope_config xml is simply an xml serialization of the GetDescriptionForScope return object.

    Thursday, July 10, 2014 8:27 AM
  • Hello

    I did not quite understand you,

    how can I use the API to retrieve the scope_config xml?

    If I use something like this 

    clientSqlDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scopeName, serverConn);
    I do not get the xml, I get information about the tables included in the scope and so on, but no xml.

    Thursday, July 10, 2014 10:53 AM
  • i meant if you use an object serializer and serialize that object as a xml, its the same as the xml in the scope_config.
    • Edited by JuneT Thursday, July 10, 2014 12:31 PM
    Thursday, July 10, 2014 12:26 PM