Click here to Skip to main content
16,004,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team,


How to find inalready in use.

I have n number of records in my table,
if a userA select a record , the particular record should be lock
means the other users should not be able to select the record until the userA updates & User B Must get a message "Record already in use".

I am Using Linq.

Linq or ADO.net

Please help me



Thanks in Advance


Regards ,

Manish Ahuja
Posted

You can use WITH(NOLOCK) in T-SQL eg. SELECT * FROM Table1 WITH (NOLOCK) and then recive that resaults in ado.net via stored procedure
 
Share this answer
 
I suggest you look into SQL table locking. There are various levels of locking you can do (e.g., lock the whole table, lock a single row, do no locking at all). The way locking works is that if userA is updating the table, userB will automatically wait until userA is finished. Once userA finishes, userB will then be able to perform a query against that table.

If you want to tell the user "Record already in use", you could create a timeout and, once that timeout expires, tell the user that the record is in use.

Or, you could create a custom locking solution by inserting a record into a table that indicates whether or not you are using another table. When you are done with using the other table, you could then delete that record from the locking indication table.

All that being said, this is the most likely solution you're after:

If you want to indicate at the row level if the record is locked, you could could have a column on the table that indicates if the row is locked. The code that locks the record will update that "IsLocked" column by setting it to "true". It will release the lock by setting it to "false". There are various ways of representing boolean values with SQL, but my favorite is a varchar(3) that stores "yes" or "no".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900