I'm trying to implement Microsoft Synchronization services into a smart device application I am developing however I seem to have hit a brick wall and I am hoping someone will be able to provide a solution. I have managed to implement synchronization so that it downloads every record in a table, however I am wanting to filter the records so only the data relating to the user is downloaded. To achieve this I have added the a WHERE Operator.kde = @kde clause to the SelectIncrementalInsertsCommand, as shown in the following code.

this.SelectIncrementalInsertsCommand.CommandText = @"IF @sync_initialized = 0 SELECT dbo.Operator.[OperatorID], [kde], [OperatorName], [Pass] FROM dbo.Operator LEFT OUTER JOIN CHANGETABLE(CHANGES dbo.Operator, @sync_last_received_anchor) CT ON CT.[OperatorID] = dbo.Operator.[OperatorID] WHERE dbo.Operator.[kde] = @kde AND (CT.SYS_CHANGE_CONTEXT IS NULL OR CT.SYS_CHANGE_CONTEXT <> @sync_client_id_binary) ELSE  BEGIN SELECT dbo.Operator.[OperatorID], [kde], [OperatorName], [Pass] FROM dbo.Operator JOIN CHANGETABLE(CHANGES dbo.Operator, @sync_last_received_anchor) CT ON CT.[OperatorID] = dbo.Operator.[OperatorID] WHERE dbo.Operator.[kde] = @kde AND (CT.SYS_CHANGE_OPERATION = 'I' AND CT.SYS_CHANGE_CREATION_VERSION  <= @sync_new_received_anchor AND (CT.SYS_CHANGE_CONTEXT IS NULL OR CT.SYS_CHANGE_CONTEXT <> @sync_client_id_binary)); IF CHANGE_TRACKING_MIN_VALID_VERSION(object_id(N'dbo.Operator')) > @sync_last_received_anchor RAISERROR (N'SQL Server Change Tracking has cleaned up tracking information for table ''%s''. To recover from this error, the client must reinitialize its local database and try again',16,3,N'dbo.Operator')  END ";

I have then declared the @kde parameter as follows.

this.SelectIncrementalInsertsCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@kde", System.Data.SqlDbType.Int));

To pass in the parameter I have added the following line to the code responsible for initiating the synchronization.

syncAgent.Configuration.SyncParameters.Add(new SyncParameter("@kde", kde));

NOTE: the kde value is an integer that is passed into my sync method

Despite these filters being added, the synchronization process seems to be completely ignoring them and downloading all the data for every operator. I have investigated this issue online and my code seems identical to numerous tutorials I have read, however it still does not work as desired.

I am fairly new to Sync Services so if anyone could provide me with information and guidance to solving this issue I will be hugely grateful

Thank You in advance

有帮助吗?

解决方案 2

I managed to fix this problem, it turned out to be some "dirty" records on the database which for some reason were affecting synchronization. Once I deleted these records everything worked as it should.

其他提示

have you tried this?

ADDING FILTER TO LOCAL DATABASE CACHE GENERATED SYNC

I would suggest you run SQL Profiler as well to see the actual commands being passed to SQL Server.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top