Showing posts with label sqlexpress. Show all posts
Showing posts with label sqlexpress. Show all posts

Thursday, March 29, 2012

Distributed data synchronization - Comparing timestamp

Hello,

I am designing a distributed application where a central SQL Server 2005 database will need to be synchronized with remote SQLExpress databases via a WebService. Data can be edited at the cental db (by our connected applications) or on the local SQLExpress dbs running on the users machines (by this disconnected application).

Now, how can I use the timestamp column to determine the most recent update. The most recent update to me is not the user that most recently invoked the syncing WebService, but the most recent time when the change was made to the data locally vs the change time at the central server. Because a user could make a change on his laptop on Monday but not synchronize it till Friday. I dont want the Mon data to overwrite data of Tues-Fri being overwritten simply based on assumption that a late sync is infact the most recent change.

The initial data will be downloaded to the local SQLExpress db via the WebService so the timestamp data in the table will come along with it.

When a user modifies data in this disconnected SQLExpress db, can that be compared to modifications on the central db using timestamps to determine if the users data being synced is older or newer than the data on the server? I understand timestamps are incremental values, but are they still sensitive to the users timezone since the central server will be a diff timezone then the user.

Timestamps are instance-level unique numbers. So you can't really compare those across instances. Why don't you use merge replication for instance? It is designed to solve problems like these. If you assistance on the replicaiton part you should post in the replication forum.|||

For ISVs that are building installable components, replication isn't too attractive. The components are meant to be quickly deployable whereas replication requires configuration to be done to create the publishers, distributers, etc.

So, basically, I would have to write a home-grown solution for conflict resolution?

Does anyone know how Microsoft is handling conflict resolution for the remote synchronization in its Project Elixir, which I believe also synchonizes disconnected data caches using webservices?

|||Then you will have to use a combination of binary_checksum or checksum along with comparison of columns or generate hash for each row using hashbytes function. You can compare rows efficiently this way and then perform the conflict resolution. This of course is no easy matter since each technique has it's own pros and cons.|||

hi,

Can I know is there anyway to compare 2 timestamp in .NET?

For eg. I got 2 timestamp, I want to know which 1 is the most recent changed.

Thanks.

Distributed data synchronization - Comparing timestamp

Hello,

I am designing a distributed application where a central SQL Server 2005 database will need to be synchronized with remote SQLExpress databases via a WebService. Data can be edited at the cental db (by our connected applications) or on the local SQLExpress dbs running on the users machines (by this disconnected application).

Now, how can I use the timestamp column to determine the most recent update. The most recent update to me is not the user that most recently invoked the syncing WebService, but the most recent time when the change was made to the data locally vs the change time at the central server. Because a user could make a change on his laptop on Monday but not synchronize it till Friday. I dont want the Mon data to overwrite data of Tues-Fri being overwritten simply based on assumption that a late sync is infact the most recent change.

The initial data will be downloaded to the local SQLExpress db via the WebService so the timestamp data in the table will come along with it.

When a user modifies data in this disconnected SQLExpress db, can that be compared to modifications on the central db using timestamps to determine if the users data being synced is older or newer than the data on the server? I understand timestamps are incremental values, but are they still sensitive to the users timezone since the central server will be a diff timezone then the user.

Timestamps are instance-level unique numbers. So you can't really compare those across instances. Why don't you use merge replication for instance? It is designed to solve problems like these. If you assistance on the replicaiton part you should post in the replication forum.|||

For ISVs that are building installable components, replication isn't too attractive. The components are meant to be quickly deployable whereas replication requires configuration to be done to create the publishers, distributers, etc.

So, basically, I would have to write a home-grown solution for conflict resolution?

Does anyone know how Microsoft is handling conflict resolution for the remote synchronization in its Project Elixir, which I believe also synchonizes disconnected data caches using webservices?

|||Then you will have to use a combination of binary_checksum or checksum along with comparison of columns or generate hash for each row using hashbytes function. You can compare rows efficiently this way and then perform the conflict resolution. This of course is no easy matter since each technique has it's own pros and cons.|||

hi,

Can I know is there anyway to compare 2 timestamp in .NET?

For eg. I got 2 timestamp, I want to know which 1 is the most recent changed.

Thanks.

sql

Thursday, March 22, 2012

DISTINCT doesnt seem to be working

Hi all,

I am using SQLEXPRESS 2005 and can't figure out why my SQL query is not working.

Select DISTINCT ads.clientid, ads.ad, ads.adid, ads.cost, ads.description, ads.bold, ads.info, ads.contact, ads.coupon, ads.logo, ads.map, ads.webpage, ads.weburl, tclients.clientname, tclients.clientphone, tclients.addNumber, tclients.addStreet, tclients.addsuite, tclients.addcity, tclients.addstate, tclients.addzipfrom tclients, adswhere tclients.clientid=ads.clientidAND AdActive=1ORDER BY COSTDESC

I expect only one row to be returned for each ads.clientid. However, every single record that matches the query is being returned, which results in multiple records with the same clientid.

This happens if it isads.clientid ortclients.clientid.

Martin

DISTINCT returns unique rows based on all columns in the query, not just the first column (clientid) that you've specified.|||

Ah - I'm glad it it working as intended and I am not going mad...

How would I go about getting what I wanted then? Just one clientid.

|||

Can't answer that.

You said what you wanted.

You showed the query you have and the columns that you want.

The two don't mix, or the distinct would have worked anyhow. You obviously have multiple records with the same clientid, and differing data. WHICH of the differing data would you like when a clientid has multiple?

Assuming your fingers have names (index,middle,ring,pinky,thumb), and your hands have names (left, right).

Please tell me the length of your finger on each hand. And I only want one 2 entries, one for each hand. And if you are left scratching your head, it's because the question doesn't match the data, and you can't answer it. If I said, tell me the length of the longest finger on each hand, NOW you can answer, or I could say tell me the length of your index finger on each hand, etc.

|||

Thanks for that post - it helped me realize what I am doing wrong in my query.

I assumed because I was ordering by COST that it would take the first record for each clientid. In your example, it would order all my fingers by length, then take the longest one from each hand.

Since I know this is not the case, I know have to figure out how to re-write the query.

|||

Motley,

This SEEMS to work, but I'm not a SQL expert, so I can't be sure it will in real data. Does it look good to you? The bolded part is what I added.

Select DISTINCT ads.clientid, ads.ad, ads.adid, ads.cost, ads.description, ads.bold, ads.info, ads.contact, ads.coupon, ads.logo, ads.map, ads.webpage, ads.weburl, tclients.clientname, tclients.clientphone, tclients.addNumber, tclients.addStreet, tclients.addsuite, tclients.addcity, tclients.addstate, tclients.addzipfrom tclients, adswhere tclients.clientid=ads.clientidAND AdActive=1AND costin (select max(ads.cost)from adsgroup by clientid)ORDER BY COSTDESC