none
How to filter without removing scope RRS feed

  • Question

  • Each and everytime I am passing and setting dynamic filter value by removing scope. Is it possible to pass dynamic parameter filter value without removing scope? If so, can any of you send me the procedure.  we are using the following code for dynamic filtering and removing scope. Thanks in advance

                    DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(ScopeTemplateName);
                    scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Customer", customer_columns, (System.Data.SqlClient.SqlConnection)provider.Connection));

                    SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning((SqlConnection)provider.Connection, scopeDesc, SqlSyncScopeProvisioningType.Template);
                    SqlSyncScopeProvisioning serverProvLocalDocId = new SqlSyncScopeProvisioning((SqlConnection)provider.Connection);

                    RemoveScope(scopeName, (SqlConnection)provider.Connection);

                    if (!serverConfig.TemplateExists(ScopeTemplateName))
                    {

                        serverConfig.ObjectSchema = "dbo";


                        SqlParameter param = new SqlParameter("@ProjectID", SqlDbType.Int);

                        serverConfig.Tables["Customer"].AddFilterColumn("document_id");
                        serverConfig.Tables["Customer"].FilterClause = "[base].[document_id]=@ProjectID";
                        serverConfig.Tables["Customer"].FilterParameters.Add(param);
                        serverConfig.Apply();

                    }

                    serverProvLocalDocId.ObjectSchema = "dbo";

                    if (!serverProvLocalDocId.ScopeExists(scopeName))
                    {
                        serverProvLocalDocId.PopulateFromTemplate(scopeName, ScopeTemplateName);

                        serverProvLocalDocId.Tables["Customer"].FilterParameters["@ProjectID"].Value = projectId;

                        serverProvLocalDocId.Apply();
                    }

    // Remove scope function

     private void RemoveScope(string scopeName, SqlConnection sqlConn)
            {
                sqlConn.Open();

                SqlCommand getScopeGuid = new SqlCommand(@" USE [" + sqlConn.Database + @"] SELECT scope_config_id FROM scope_info WHERE sync_scope_name = '" + scopeName + "'", sqlConn);
                var reader = getScopeGuid.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    var id = reader.GetGuid(0);
                    reader.Close();
                    SqlCommand deleteScope = new SqlCommand(@"DELETE FROM scope_info WHERE scope_config_id = '" + id + @"'; DELETE FROM scope_parameters WHERE sync_scope_name = '" + scopeName + @"';  ", sqlConn);//DELETE FROM scope_config WHERE config_id = '" + id + @"';
                    deleteScope.ExecuteNonQuery();
                }
            }


    • Edited by gk23 Wednesday, June 6, 2012 10:20 AM
    Wednesday, June 6, 2012 10:18 AM

All replies

  • sync fx doesnt support dynamic filtering. using the scope template is the closest you can get to creating scopes with different filter values without having to define the scope structure everytime.

    also, instead of deleting the scope record manually, use the deprovisioning API.

    Wednesday, June 6, 2012 10:54 AM
    Moderator