Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you only update changed records 1

Status
Not open for further replies.

G00GLER

Instructor
May 17, 2005
57
0
0
US
i understand if i am running an Application that loads in xml, i make changes and i call dataadapter to update the sql table.

what i don't understand is if i have an app that is mostly offline. several times app is opened and closed only saving xml file to hard drive, on the rare occasion it's online, user has option to SYNC to master DB.

in theory he hits button and only updates records he changed, then downloads who table into xml, replacing xml file on harddrive so that he has lasted copy of master_table.

i'm afraid an unchanged record on my harddrive will overwrite a recently changed record on the master_table.

All pointers, references appreciated.
 
If you have multiple users, there are two choices, optimistic or pessimistic locking.

With the first, when you get the records from the database and create the XML, you add a lock token to the XML for each 'row' (some people add a counter column to the DB table, I prefer using the binary checksum of the columns). This acts as an 'update ticket'. Your user updates his XML, and when he re-syncs he presents the token. Under the covers, you do an UPDATE table SET .... WHERE key = ... AND BINARY_CHECKSUM() = token. If the table row has been changed in the meantime by another user, the checksum doesn't match and the update fails. If it is still the same, then the update is allowed as you know you aren't overwriting data. Works best when the proportion of reads to updates is high.

The second is much cruder. When you export the data to XML, you lock it so no-one else can update it. Works best when almost all users will be updating, but at the expense of data availability.

HTH
 
thanks for responding stevexf

i will into your first suggestion there will be 50 xml files one each on 50 some desktops.

i'll likely add a counter column to the DB Table just because more comofortable and have a tight deadline.

but i am going to look into your checksum later it sounds like the better practice.

again thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top