locked
How do filters do in sync? RRS feed

  • Question

  •  

    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";  
                builder builder.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
    Friday, February 6, 2009 11:41 AM

Answers

  • Hi.

    Discovered that the problem is that block of code below:

                SqlCommand anchorCmdServer = new SqlCommand();  
                anchorCmdServer.CommandType = CommandType.Text;  
                anchorCmdServer.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = min_active_rowversion() - 1";  // for SQL Server 2005 SP2, use "min_active_rowversion() - 1"  
                anchorCmdServer.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.DateTime).Direction = ParameterDirection.Output;  
     
                serverSyncProvider.SelectNewAnchorCommand = anchorCmdServer;  
     
                SqlCommand anchorCmdClient = new SqlCommand();  
                anchorCmdClient.CommandType = CommandType.Text;  
                anchorCmdClient.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = @@DBTS";  
                anchorCmdClient.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.DateTime).Direction = ParameterDirection.Output; 

    The anchorCmdServer is returing 1910-12-15 00:00:00.000

    the anchorCmdClient is returing 1900-01-01 00:00:13.333

    So the sychronize isn't happening.

    What am I doing the error?

    help me, please.

    Marcos Antonio Aguiar Jr
    Monday, February 9, 2009 5:20 PM

All replies

  • Hi Marcos,

    Would you please provide more details on what kind of error you got? Do you get any Exception during sync? Does the above sample sync any data at all? 

    Microsoft Sync Framework
    Friday, February 6, 2009 6:07 PM
  •  Hi.

    The message  error is : "Unable to enumerate changes at the DbServerSyncProvider for table 'CESTAPRODUTOS' in synchronization group 'CESTAPRODUTOS'."

    I'm doing a sync between SQL Server Enterprise (Service) e SQL Server Express (Client), with an example to site MSDN.

    The error happen in metod following in class SqlExpressClientSyncProvider

     public override SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)  
            {  
                // neet to set the LastReceivedAnchor as the LastSentAnchor since   
                // DbServerSyncProvider operates from the server's perspective, so  
                // we swap the two fields temporarily.   
                foreach (SyncTableMetadata metaTable in groupMetadata.TablesMetadata)  
                {  
                    SyncAnchor temp = metaTable.LastReceivedAnchor;  
                    metaTablemetaTable.LastReceivedAnchor = metaTable.LastSentAnchor;  
                    metaTable.LastSentAnchor = temp;  
                }  
     
                SyncContext context = _dbSyncProvider.GetChanges(groupMetadata, syncSession);  
     
                //swap them back for consistency  
                foreach (SyncTableMetadata metaTable in groupMetadata.TablesMetadata)  
                {  
                    SyncAnchor temp = metaTable.LastReceivedAnchor;  
                    metaTablemetaTable.LastReceivedAnchor = metaTable.LastSentAnchor;  
                    metaTable.LastSentAnchor = temp;  
                }  
                return context;  
            }  
     

    Can you help me with these information?

    Thanks.
    Marcos Antonio Aguiar Jr
    Friday, February 6, 2009 6:43 PM
  •  Hi.

    I resolved the problem. One parameter was declared twice.

    Now, I have other problem. My data not synchronize.

    The Code:

            public SyncStatistics Synchronization()  
            {  
                // Setando Conexão  
                syncAgent.RemoteProvider = serverSyncProvider;  
                syncAgent.LocalProvider = clientSyncProvider;  
                serverSyncProvider.Connection = connServer;  
                clientSyncProvider.Connection = connClient;  
     
                // Chamando rotinas para Sincronização  
                this.SyncCestaProduto();  
     
                // Criando ponto de Ancora  
                SqlCommand anchorCmdServer = new SqlCommand();  
                anchorCmdServer.CommandType = CommandType.Text;  
                anchorCmdServer.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = min_active_rowversion() - 1";  // for SQL Server 2005 SP2, use "min_active_rowversion() - 1"  
                anchorCmdServer.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.DateTime).Direction = ParameterDirection.Output;  
     
                serverSyncProvider.SelectNewAnchorCommand = anchorCmdServer;  
     
                SqlCommand anchorCmdClient = new SqlCommand();  
                anchorCmdClient.CommandType = CommandType.Text;  
                anchorCmdClient.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = @@DBTS";  
                anchorCmdClient.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.DateTime).Direction = ParameterDirection.Output;  
     
                clientSyncProvider.SelectNewAnchorCommand = anchorCmdClient;  
     
                // Sincronizando dados  
                return syncAgent.Synchronize();  
            }  
     
            private void SyncCestaProduto()  
            {  
                // Setando parametros  
                if (Consts.Acesso.Usuario.IsGD)  
                    syncAgent.Configuration.SyncParameters.Add(new SyncParameter("@CodigoDistrito", Consts.Acesso.Usuario.Distrito));  
                else 
                    syncAgent.Configuration.SyncParameters.Add(new SyncParameter("@CodigoAreaAtuacao", Consts.Acesso.Usuario.AreaAtuacao));  
                  
                //Criando SyncTables e SyncGroups  
                SyncGroup CestaSyncGroup = new SyncGroup("CESTAPRODUTOS");  
     
                SyncTable tableCesta = new SyncTable("CESTAPRODUTOS");  
                tableCesta.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;  
                tableCesta.SyncDirection = SyncDirection.Bidirectional;  
                tableCesta.SyncGroup = CestaSyncGroup;  
     
                syncAgent.Configuration.SyncTables.Add(tableCesta);  
     
                SqlParameter filterParameter = new SqlParameter("@CodigoAreaAtuacao", SqlDbType.NVarChar);  
     
                SqlSyncAdapterBuilder builderCesta = new SqlSyncAdapterBuilder(connServer);  
     
                builderCesta.TableName = "CESTAPRODUTOS";  
                builderCesta.TombstoneTableName = builderCesta.TableName + "_Tombstone";  
                builderCesta.SyncDirection = SyncDirection.Bidirectional;  
                builderCesta.CreationTrackingColumn = "CreationDate";  
                builderCesta.UpdateTrackingColumn = "LastEditDate";  
                builderCesta.DeletionTrackingColumn = "DeletionDate";  
     
                builderCesta.DataColumns.Add("CODIGOPRODUTO");  
                builderCesta.DataColumns.Add("CODIGOAREAATUACAO");  
                builderCesta.DataColumns.Add("DATAATUALIZACAO");  
                builderCesta.DataColumns.Add("USUARIOATUALIZACAO");  
                builderCesta.DataColumns.Add("UPLOAD");  
     
                builderCesta.TombstoneDataColumns.Add("CODIGOPRODUTO");  
                builderCesta.TombstoneDataColumns.Add("CODIGOAREAATUACAO");  
     
                string FilterClause = "CODIGOAREAATUACAO=@CodigoAreaAtuacao";  
     
                builderCesta.FilterClause = FilterClause;  
                builderCesta.FilterParameters.Add(filterParameter);  
                builderCesta.TombstoneFilterClause = FilterClause;  
                builderCesta.TombstoneFilterParameters.Add(filterParameter);  
     
                // Gerando comandos para atualização dos dados  
                SyncAdapter customerSyncAdapter = builderCesta.ToSyncAdapter();  
                customerSyncAdapter.TableName = "CESTAPRODUTOS";  
     
                // Instrução SQL para inserir dos dados  
                customerSyncAdapter.InsertCommand = new System.Data.SqlClient.SqlCommand();  
                customerSyncAdapter.InsertCommand.CommandText = @"INSERT INTO dbo.CESTAPRODUTOS (" +  
                                                                 " [CODIGOPRODUTO]," +  
                                                                 " [CODIGOAREAATUACAO]," +  
                                                                 " [DATAATUALIZACAO]," +  
                                                                 " [USUARIOATUALIZACAO], " +  
                                                                 " [UPLOAD], " +  
                                                                 " [LastEditDate], " +  
                                                                 " [CreationDate] " +  
                                                                 " ) VALUES ( " +  
                                                                 " @CODIGOPRODUTO, " +  
                                                                 " @CODIGOAREAATUACAO," +  
                                                                 " @DATAATUALIZACAO, " +  
                                                                 " @USUARIOATUALIZACAO," +  
                                                                 " @UPLOAD, " +  
                                                                 " @LastEditDate, " +  
                                                                 " @CreationDate) SET @sync_row_count = @@rowcount";  
     
                customerSyncAdapter.InsertCommand.CommandType = System.Data.CommandType.Text;  
                customerSyncAdapter.InsertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CODIGOPRODUTO", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.InsertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CODIGOAREAATUACAO", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.InsertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@DATAATUALIZACAO", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.InsertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@USUARIOATUALIZACAO", System.Data.SqlDbType.VarChar));  
                customerSyncAdapter.InsertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UPLOAD", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.InsertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@LastEditDate", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.InsertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreationDate", System.Data.SqlDbType.DateTime));  
                System.Data.SqlClient.SqlParameter insertcommand_sync_row_countParameter = new System.Data.SqlClient.SqlParameter("@sync_row_count", System.Data.SqlDbType.Int);  
                insertcommand_sync_row_countParameter.Direction = System.Data.ParameterDirection.Output;  
                customerSyncAdapter.InsertCommand.Parameters.Add(insertcommand_sync_row_countParameter);  
     
                // Instrução SQL para exclusão dos dados  
                customerSyncAdapter.DeleteCommand = new System.Data.SqlClient.SqlCommand();  
                customerSyncAdapter.DeleteCommand.CommandText = "DELETE FROM dbo.CESTAPRODUTOS " +  
                                                                " WHERE ([CODIGOPRODUTO] = @CODIGOPRODUTO AND " +  
                                                                "        [CODIGOAREAATUACAO] = @CODIGOAREAATUACAO) AND " +  
                                                                "        (@sync_force_write = 1 OR " +  
                                                                "         ([LastEditDate] <= @sync_last_received_anchor)) SET @sync_row_count = @@rowcount";  
                customerSyncAdapter.DeleteCommand.CommandType = System.Data.CommandType.Text;  
                customerSyncAdapter.DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CODIGOPRODUTO", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CODIGOAREAATUACAO", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_force_write", System.Data.SqlDbType.Bit));  
                customerSyncAdapter.DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.DateTime));  
                System.Data.SqlClient.SqlParameter deletecommand_sync_row_countParameter = new System.Data.SqlClient.SqlParameter("@sync_row_count", System.Data.SqlDbType.Int);  
                deletecommand_sync_row_countParameter.Direction = System.Data.ParameterDirection.Output;  
                customerSyncAdapter.DeleteCommand.Parameters.Add(deletecommand_sync_row_countParameter);  
     
                // Instrução SQL para atualização dos dados  
                customerSyncAdapter.UpdateCommand = new System.Data.SqlClient.SqlCommand();  
                customerSyncAdapter.UpdateCommand.CommandText = @"UPDATE dbo.CESTAPRODUTOS SET" +  
                                                                 "       [DATAATUALIZACAO] = @DATAATUALIZACAO, " +  
                                                                 "       [USUARIOATUALIZACAO] = @USUARIOATUALIZACAO, " +  
                                                                 "       [UPLOAD] = @UPLOAD, " +  
                                                                 "       [LastEditDate] = @LastEditDate," +  
                                                                 "       [CreationDate] = @CreationDate " +  
                                                                 " WHERE ([CODIGOPRODUTO] = @CODIGOPRODUTO " +  
                                                                 "   AND [CODIGOAREAATUACAO] = @CODIGOAREAATUACAO) " +  
                                                                 "   AND (@sync_force_write = 1 OR " +  
                                                                 "       ([LastEditDate] <= @sync_last_received_anchor)) SET @sync_row_count = @@rowcount";  
                  
                customerSyncAdapter.UpdateCommand.CommandType = System.Data.CommandType.Text;  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@DATAATUALIZACAO", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@USUARIOATUALIZACAO", System.Data.SqlDbType.VarChar));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UPLOAD", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@LastEditDate", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreationDate", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CODIGOPRODUTO", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CODIGOAREAATUACAO", System.Data.SqlDbType.Decimal));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_force_write", System.Data.SqlDbType.Bit));  
                customerSyncAdapter.UpdateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.DateTime));  
                System.Data.SqlClient.SqlParameter updatecommand_sync_row_countParameter = new System.Data.SqlClient.SqlParameter("@sync_row_count", System.Data.SqlDbType.Int);  
                updatecommand_sync_row_countParameter.Direction = System.Data.ParameterDirection.Output;  
                customerSyncAdapter.UpdateCommand.Parameters.Add(updatecommand_sync_row_countParameter);  
     
                // Instrução SQL que traz os dados que serão incluidos  
                customerSyncAdapter.SelectIncrementalInsertsCommand = new System.Data.SqlClient.SqlCommand();  
     
                if (Consts.Acesso.Usuario.IsGD)  
                {  
                    Instrucao = "SELECT [CES.CODIGOPRODUTO], " +  
                                "       [CES.CODIGOAREAATUACAO], " +  
                                "       [CES.DATAATUALIZACAO], " +  
                                "       [CES.USUARIOATUALIZACAO], " +  
                                "       [CES.UPLOAD], " +  
                                "       [CES.LastEditDate], " +  
                                "       [CES.CreationDate] " +  
                                "  FROM dbo.CESTAPRODUTOS CES INNER JOIN" +  
                                "       dbo.AREAATUACAO AAT ON AAT.CODIGOAREAATUACAO = CES.CODIGOAREAATUACAO INNER JOIN" +  
                                "       dbo.DISTRITO DIS ON DIS.CODIGODISTRITO = AAT.CODIGODISTRITO" +  
                                " WHERE [DIS.CODIGODISTRITO] = @CodigoDistrito" +  
                                "   AND ([CreationDate] > @sync_last_received_anchor AND " +  
                                "        [CreationDate] <= @sync_new_received_anchor)";  
                      
                    customerSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CodigoDistrito", Consts.Acesso.Usuario.Distrito));  
                }  
                else 
                {  
                    Instrucao = "SELECT [CODIGOPRODUTO], " +  
                                "       [CODIGOAREAATUACAO], " +  
                                "       [DATAATUALIZACAO], " +  
                                "       [USUARIOATUALIZACAO], " +  
                                "       [UPLOAD], " +  
                                "       [LastEditDate], " +  
                                "       [CreationDate] " +  
                                "  FROM dbo.CESTAPRODUTOS " +  
                                " WHERE ([CreationDate] > @sync_last_received_anchor AND" +  
                                "        [CreationDate] <= @sync_new_received_anchor)" +  
                                "   AND [CODIGOAREAATUACAO] = @CodigoAreaAtuacao";  
     
                    customerSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CodigoAreaAtuacao", Consts.Acesso.Usuario.AreaAtuacao));  
                }  
     
                customerSyncAdapter.SelectIncrementalInsertsCommand.CommandText = Instrucao;  
                customerSyncAdapter.SelectIncrementalInsertsCommand.CommandType = System.Data.CommandType.Text;  
                customerSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.SelectIncrementalInsertsCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.DateTime));  
     
                // Instrução SQL que traz os dados que serão Excluídos  
                customerSyncAdapter.SelectIncrementalDeletesCommand = new System.Data.SqlClient.SqlCommand();  
     
                Instrucao = "SELECT [CODIGOPRODUTO]," +  
                            "       [CODIGOAREAATUACAO], " +  
                            "       [DeletionDate] " +  
                            "  FROM dbo.CESTAPRODUTOS_Tombstone " +  
                            " WHERE (@sync_initialized = 1 AND " +  
                            "        [DeletionDate] > @sync_last_received_anchor AND " +  
                            "        [DeletionDate] <= @sync_new_received_anchor)";  
     
                customerSyncAdapter.SelectIncrementalDeletesCommand.CommandText = Instrucao;  
     
                customerSyncAdapter.SelectIncrementalDeletesCommand.CommandType = System.Data.CommandType.Text;  
                customerSyncAdapter.SelectIncrementalDeletesCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_initialized", System.Data.SqlDbType.Bit));  
                customerSyncAdapter.SelectIncrementalDeletesCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.SelectIncrementalDeletesCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.DateTime));  
     
                // Instrução SQL que traz os dados que serão Atualizadas  
                customerSyncAdapter.SelectIncrementalUpdatesCommand = new System.Data.SqlClient.SqlCommand();  
     
                if (Consts.Acesso.Usuario.IsGD)  
                {  
                    Instrucao = "SELECT [CES.CODIGOPRODUTO], " +  
                                "       [CES.CODIGOAREAATUACAO], " +  
                                "       [CES.DATAATUALIZACAO], " +  
                                "       [CES.USUARIOATUALIZACAO], " +  
                                "       [CES.UPLOAD], " +  
                                "       [CES.LastEditDate], " +  
                                "       [CES.CreationDate] " +  
                                "  FROM dbo.CESTAPRODUTOS CES INNER JOIN" +  
                                "       dbo.AREAATUACAO AAT ON AAT.CODIGOAREAATUACAO = CES.CODIGOAREAATUACAO INNER JOIN" +  
                                "       dbo.DISTRITO DIS ON DIS.CODIGODISTRITO = AAT.CODIGODISTRITO" +  
                                " WHERE [DIS.CODIGODISTRITO] = @CodigoDistrito" +  
                                "   AND ([CES.LastEditDate] > @sync_last_received_anchor AND " +  
                                "        [CES.LastEditDate] <= @sync_new_received_anchor AND " +  
                                "        [CES.CreationDate] <= @sync_last_received_anchor)";  
     
                    customerSyncAdapter.SelectIncrementalUpdatesCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CodigoDistrito", Consts.Acesso.Usuario.Distrito));  
                }  
                else 
                {  
                    Instrucao = "SELECT [CODIGOPRODUTO], " +  
                                "       [CODIGOAREAATUACAO], " +  
                                "       [DATAATUALIZACAO], " +  
                                "       [USUARIOATUALIZACAO], " +  
                                "       [UPLOAD], " +  
                                "       [LastEditDate], " +  
                                "       [CreationDate] " +  
                                "  FROM dbo.CESTAPRODUTOS " +  
                                " WHERE ([LastEditDate] > @sync_last_received_anchor AND " +  
                                "        [LastEditDate] <= @sync_new_received_anchor AND " +  
                                "        [CreationDate] <= @sync_last_received_anchor)" +  
                                "   AND [CODIGOAREAATUACAO] = @CodigoAreaAtuacao";  
     
                    customerSyncAdapter.SelectIncrementalUpdatesCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CodigoAreaAtuacao", Consts.Acesso.Usuario.AreaAtuacao));  
                }  
     
                customerSyncAdapter.SelectIncrementalUpdatesCommand.CommandText = Instrucao;  
     
                customerSyncAdapter.SelectIncrementalUpdatesCommand.CommandType = System.Data.CommandType.Text;  
                customerSyncAdapter.SelectIncrementalUpdatesCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_last_received_anchor", System.Data.SqlDbType.DateTime));  
                customerSyncAdapter.SelectIncrementalUpdatesCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sync_new_received_anchor", System.Data.SqlDbType.DateTime));  
     
                serverSyncProvider.SyncAdapters.Add(customerSyncAdapter);  
                SyncCestaProdutoAddClient(clientSyncProvider);  
            } 



    What am I the wrong?

    Thanks.


    Marcos Antonio Aguiar Jr
    Friday, February 6, 2009 7:49 PM
  • Hi.

    Discovered that the problem is that block of code below:

                SqlCommand anchorCmdServer = new SqlCommand();  
                anchorCmdServer.CommandType = CommandType.Text;  
                anchorCmdServer.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = min_active_rowversion() - 1";  // for SQL Server 2005 SP2, use "min_active_rowversion() - 1"  
                anchorCmdServer.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.DateTime).Direction = ParameterDirection.Output;  
     
                serverSyncProvider.SelectNewAnchorCommand = anchorCmdServer;  
     
                SqlCommand anchorCmdClient = new SqlCommand();  
                anchorCmdClient.CommandType = CommandType.Text;  
                anchorCmdClient.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = @@DBTS";  
                anchorCmdClient.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.DateTime).Direction = ParameterDirection.Output; 

    The anchorCmdServer is returing 1910-12-15 00:00:00.000

    the anchorCmdClient is returing 1900-01-01 00:00:13.333

    So the sychronize isn't happening.

    What am I doing the error?

    help me, please.

    Marcos Antonio Aguiar Jr
    Monday, February 9, 2009 5:20 PM