How to fix Bi-Directional Synchronization?

2019-08-28 07:53发布

问题:

I have a problem with the logic of my synchronization.

Client Database Table Column:
- LastSync (Datetime - This tracks when the last sync occurs)
- LastUpdated (Datetime - This tracks when the data is last updated regardless if its the client or server who updated the data)

Server Database Table Column:
- ServerUpdate (Datetime - This tracks when the server last updated the data)
- ClientUpdate (Datetime - This tracks when the client/user updated the data)

My problem:

To keep the client/user's data updated I get the data from the server whose ServerUpdate is greater than the ClientUpdate (Sample SQL: "Select ID FROM tblContacts WHERE ServerUpdate > ClientUpdate") then I update the client side (meaning I updated the data and the LastSync and LastUpdated).

The problem is when I sync the data of the client it always get the data whose ServerUpdate is greater than the ClientUpdate even though the data is already updated.

For example, the client sync the New Password (that the server changed) of my user that means the ServerUpdate is greater than the ClientUpdate. When you sync the data it will be updated in the client side. However, when you sync again the server is still passing the same data even though the data is already updated.

What can I do to get only the data that is not yet updated even if the ServerUpdate is greater than ClientUpdate?