Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
I want to lock a record so that no one except myself can access that record.

I heard locking concept in SQLServer.

But I don't know how to implement it.

Example:

I have logged into a user name say 'John'

Only the username with such name can access this record.


How to do this in SQLServer and implement in windows forms using C#.
Posted

Hello friend, the following link might help you:

6 ways of doing locking in .NET (Pessimistic and optimistic)[^]

- DD
 
Share this answer
 
There is no way to lock a record (or table or index or page or any other SQL 'object') using programming techniques. SQL locks are created by SQL while executing different queries (transactions). You can learn a lot about locking here: http://technet.microsoft.com/en-us/library/ms190615(v=sql.105).aspx[^]
That all means that you have to develop (or find on the web) a solution for yourself...The main ideas are:
1. Record the PK of the row to lock
2. Check your records upon access
3. Clean record when appropriate (explicit release or time-out)
 
Share this answer
 
v2
You are talking about security rather than locking. You should limit access to the database then set up role-based security in your code. When a user tries to view/change data, check their credentials and limit their access in your code rather than by locking the database
 
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