Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Database lock in Entity framework

Posted on 2014-03-31
3
Medium Priority
?
2,854 Views
Last Modified: 2014-12-06
Hi,

I want to lock table and only one user should able to view /update particular record.
I am using MVC 4.0, entity framework 6.0. Can any one tell me how to do it.

What if the browser hanged and user restart/refresh the browser ?
0
Comment
Question by:Vikash p
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 1000 total points
ID: 39967419
" to lock table and only one user should able to view /update particular record."
You should never do that using SQL locks but some application locking mechanism and this should serve as a partial answer to your second question. If your "usera" locked a record and gest disconnected before "Save" you store that "UserID" [NOT the session ID which will be obviously gone] on the locked row in the SQL Table so next time the same user comes in will the app code will be able to retrieve for edit all previously locked row(s).
At the end you remove(make it NULL) the App UserId from that record so anyone else can work with it.
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1000 total points
ID: 39967560
Hi bhanjpur;

Entity Framework works in a disconnected model, It connects to the database gets the records and then disconnects. It does this for all types of transactions. Entity Framework uses optimistic concurrency. When a user updates a record in the database it first checks to make sure that the record has not been modified since it first got the record. If the record has been modified since you got the record it throws an exception. This web page, Optimistic Concurrency Patterns, shows some ways to handle the exceptions.
0
 
LVL 3

Expert Comment

by:bromose
ID: 40484531
Hi.
Think you should use "Optimistic concurrency" (the recomended way by Microsoft). You will find a guide on "how to do" here: Handling Concurrency with the Entity Framework 6 in an ASP.NET
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question