none
How do filters do in sync? RRS feed

  • Pergunta

  •  

    Hi

    I have a table with the following definition:

    IDProduct    NUMERIC(10),
    IDRegion     NUMERIC(10)


    In the table client I have three data:

    IDRegion       IDProduct
       3               1
       4               1
       3               2

    I want to synchronize the client data into the server but I want to send the server just IDRegion equals 3.

    I'm doing the code following:

        public class AgenteExtension  
        {  
            SqlConnection conn = new SqlConnection(DFS.Properties.Settings.Default.ServerDFSConnectionString);  
            SqlCeClientSyncProvider clientSyncProvider = new SqlCeClientSyncProvider(DFS.Properties.Settings.Default.ClientDFSConnectionString);  
     
            public SyncStatistics SyncCestaProduto()  
            {  
                DbServerSyncProvider serverSyncProvider = new DbServerSyncProvider();  
                serverSyncProvider.Connection = conn;  
     
                SyncAgent syncAgent = new SyncAgent();  
                syncAgent.RemoteProvider = serverSyncProvider;  
                syncAgent.LocalProvider = clientSyncProvider;  
     
                SyncGroup CestaSyncGroup = new SyncGroup("CESTAPRODUTOS");  
     
                SyncTable SyncTableCesta = new SyncTable("CESTAPRODUTOS");  
                SyncTableCesta.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;  
                SyncTableCesta.SyncDirection = SyncDirection.UploadOnly;  
                SyncTableCesta.SyncGroup = CestaSyncGroup;  
                syncAgent.Configuration.SyncTables.Add(SyncTableCesta);  
     
                syncAgent.Configuration.SyncParameters.Add(new SyncParameter("@CodigoAreaAtuacao", Consts.Acesso.Usuario.AreaAtuacao));  
     
                SqlCommand selectNewAnchorCommand = new SqlCommand();  
                string newAnchorVariable = "@" + SyncSession.SyncNewReceivedAnchor;  
                selectNewAnchorCommand.CommandText = "SELECT " + newAnchorVariable + " = min_active_rowversion() - 1";  
                selectNewAnchorCommand.Parameters.Add(newAnchorVariable, SqlDbType.Timestamp);  
                selectNewAnchorCommand.Parameters[newAnchorVariable].Direction = ParameterDirection.Output;  
                selectNewAnchorCommand.Connection = conn;  
                serverSyncProvider.SelectNewAnchorCommand = selectNewAnchorCommand;  
     
                SqlParameter filterParameter = new SqlParameter("@CodigoAreaAtuacao", SqlDbType.NVarChar);  
     
                SqlSyncAdapterBuilder builder = new SqlSyncAdapterBuilder(conn);           
     
                builder.TableName = "CESTAPRODUTOS";  
                builderbuilder.TombstoneTableName = builder.TableName + "_Tombstone";  
                builder.SyncDirection = SyncDirection.UploadOnly;  
                builder.CreationTrackingColumn = "CreationDate";  
                builder.UpdateTrackingColumn = "LastEditDate";  
                builder.DeletionTrackingColumn = "DeletionDate";  
     
                builder.DataColumns.Add("CODIGOPRODUTO");  
                builder.DataColumns.Add("CODIGOAREAATUACAO");  
                builder.DataColumns.Add("DATAATUALIZACAO");  
                builder.DataColumns.Add("USUARIOATUALIZACAO");  
                builder.DataColumns.Add("UPLOAD");  
                //builder.DataColumns.Add("LastEditDate");  
                //builder.DataColumns.Add("CreationDate");  
     
                builder.TombstoneDataColumns.Add("CODIGOPRODUTO");  
                builder.TombstoneDataColumns.Add("CODIGOAREAATUACAO");  
                //builder.TombstoneDataColumns.Add("DeletionDate");  
     
                string FilterClause = "CODIGOAREAATUACAO=@CodigoAreaAtuacao";  
     
                builder.FilterClause = FilterClause;  
                builder.FilterParameters.Add(filterParameter);  
                builder.TombstoneFilterClause = FilterClause;  
                builder.TombstoneFilterParameters.Add(filterParameter);  
     
                SyncAdapter customerSyncAdapter = builder.ToSyncAdapter();  
                customerSyncAdapter.TableName = "CESTAPRODUTOS";  
                serverSyncProvider.SyncAdapters.Add(customerSyncAdapter);  
     
                return syncAgent.Synchronize();  
            }  
        }  
    }  
     



    What am I doing wrong? Please, help me.

    Thank you in advanced


    Marcos Antonio Aguiar Jr
    sexta-feira, 6 de fevereiro de 2009 11:05