Question : Data Lock & Threading

Dear All

Suppose I have 1 application which can be accessed by users at the same time (no matter whether it is web app or windows app), and I want to lock 1 table/record as long as one user open that business form, how can I do that? (In this case, I want other users not be able to overwrite the 1st user if he/she makes some changes. )


Will SQL server or sqlcommand in dot net automatically do this? Or shall I use multi-thread (or other way) to control that?


Thanks heaps!

Answer : Data Lock & Threading

faiga16 - That opens up a can of worms. Besides, the characteristics of the ADO.NET model do not lend themselves to this kind of approach. Most data-driven technologies this days work in a disconnected mode, and do not persist (i.e. connect, get my records, build in-memory container, destroy connection).

If I am reading this right, Chenyuhao is trying to prevent a series of records from being modified while they are being edited by a user, through a user interface. The disconnected nature of .NET -and most other data-driven technologies these days make placing such controls on the database layer nearly impossible. Instead, a work-around would be to check-out these records or record by flagging them as uneditable or unavailable while the user has this form open and making changes. Effectively placing the responsability to avoid concurrency on the application. Much in the way that Source Safe or other content management tools allow for exclusive write-access to objects while checked-out by any one user.

Also, the XLOCK / ROWLOCK would only instate a row or table level lock while the query was running. Once the results are returned, the locks dissappear. And that won't server the purpose.
Random Solutions  
 
programming4us programming4us