none
Can a Sync Template contain Multiple Tables with parameter filtering? RRS feed

  • Question

  • I'm trying to create a parameter scope template which contains 3 tables, each of which have a column called LibraryID that I want to filter on. Just filtering on one column in each table. When I try to apply my changes on the SQLSyncScopeProvisioning object, I get the error "Must declare the Scalar variable @LibraryID2". Here is my code:

     

                SqlConnection serverConn = new SqlConnection("Data Source=MyServer; Initial Catalog=MyDB; Integrated Security=True");
                DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("MyParameterTemplate");
                scopeDesc.UserComment = "My Description goes here.";

                DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Schema1.Table1", serverConn);
                scopeDesc.Tables.Add(tableDesc);

                tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Schema1.Table2", serverConn);
                scopeDesc.Tables.Add(tableDesc);

                tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Schema1.Table3", serverConn);
                scopeDesc.Tables.Add(tableDesc);

                SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc, SqlSyncScopeProvisioningType.Template);
                SqlParameter param;

                serverProvision.Tables["Schema1.Table1"].AddFilterColumn("LibraryID");
                serverProvision.Tables["Schema1.Table1"].FilterClause = "[side].[LibraryID] = @LibraryID";
                param = new SqlParameter("@LibraryID", System.Data.SqlDbType.Int);
                serverProvision.Tables["Schema1.Table1"].FilterParameters.Add(param);

                serverProvision.Tables["Schema1.Table2"].AddFilterColumn("LibraryID");
                serverProvision.Tables["Schema1.Table2"].FilterClause = "[side].[LibraryID] = @LibraryID2";
                SqlParameter param2 = new SqlParameter("@LibraryID2", System.Data.SqlDbType.Int);
                serverProvision.Tables["Schema1.Table2"].FilterParameters.Add(param2);

                serverProvision.Tables["Schema1.Table3"].AddFilterColumn("LibraryID");
                serverProvision.Tables["Schema1.Table3"].FilterClause = "[side].[LibraryID] = @LibraryID3";
                SqlParameter param3 = new SqlParameter("@LibraryID3", System.Data.SqlDbType.Int);
                serverProvision.Tables["Schema1.Table3"].FilterParameters.Add(param3);

                serverProvision.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);

                // start the provisioning process
                serverProvision.Apply();

    I'm starting to think that these templates can only contain one table in each, but would like confirmation on that.

    Thanks for the help,

    Jim Osborne



    • Edited by Jim Osborne Monday, September 15, 2014 2:48 PM error
    Monday, September 15, 2014 2:31 PM

All replies

  • you should be able to have multiple tables in a template with same or varying filter conditions/parameters
    Wednesday, September 17, 2014 12:56 PM
    Moderator