sql server - How to Update and sync a Database tables at exactly same time? -


i need sync(upload first remote db-download mobile device next) db tables remote db mobile device (which may insert/update/delete rows multiple tables).

the remote db performs other operation based on uploaded sync data.when sync continues download data mobile device remote db still performing previous tasks , leads sync fail. 'critical condition' both 'sync , db-operations' want access remote databse. how solve issue? possible sync db , operate on same db @ time?

am using sql server 2008 db , mobilink sync.

edit: operations in sequence:

1.a iphone loaded application uses mobilink sync data.

2.sync means upload(from device remote db)followed download(from remote db device).

3.remote db means consolidated db ; device db ultralite db.

4.remote db has triggers fire when tables updated.

5.an upload device remote fire triggers when sync upload finished.

6.very next moment upload finished download device starts.

7.exactly same moment db triggers fire.

8.now deadlock between db sync(-download) , trigger(update queries included within) operations occur.

9.sync fails error saying cannot access tables.

my understanding of system following:

  1. mobile application sends update statement sql server db.
  2. there on update trigger, updates around 30 tables (= @ least 30 update statements in trigger + 1 main update statement)
  3. updateis executed in single transaction. transaction ends when trigger completes updates.
  4. mobile application not wait update finish , sends multiple select statements data database.
  5. these selectstatements query same tables trigger above updating.
  6. blocking , deadlocks occur @ query user trigger not completing updates before selects , keeps lock on tables.

when optimizing trying make our processes less easy computer, achieve same result in less iterations , use less resources or resources more available/less overloaded.

my suggestions design:

  1. use parametrized sps. every time sql server receives statement creates execution plan. 1 update statement trigger db needs @ least 31 execution plan. happens on busy production environment every connection every time app updates db. big waste.

  2. how sps reduce blocking? have 1 transaction 31 queries, locks issued against tables involved , held until transaction commits. sp you'll have 31 small transaction , 1-2 tables locked @ time.

another question address: how asynchronous updates database? there feature in sql server called service broker. allows process message queue (rows queue table) automatically: monitors queue, takes messages , processing specify , deletes processes messages queue.

for example, save parameters sps - messages - , service broker executes sp parameters.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -