المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Synchronisation in Multi Server environment



C# Programming
12-26-2009, 10:11 AM
I have a process which can be run from any number of servers. All of them access the same database. How do I synchronize the severs data access?

Here are the details.

My common database server has a table T1. It has columns C1, C2 and C3.

My process has the following steps.
1. Read T1 table.
2. If there is any row with value V1 for C1, wait in a loop and go to step-1.
3. If there are no such rows, insert a row with V1 for C1 and appropriate values for the rest of the columns.
4. Start my business logic.
5. Once the business logic is complete, delete the row entered in step-3.

Now the same process runs from different servers. So there is a chance that 2 or more processes will do steps 1 and 2 simultaneously and might end up creating 2 or more rows with V1 value for C1. I don't want that to happen. How will I make sure only once process can perform steps 1 and 2 at a time? I can not use lock and monitor to synchronize the access as I am running from different process spaces.

How do I do it then?