Solved

Database lock in Entity framework

Posted on 2014-03-31
3
2,161 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 250 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 63

Accepted Solution

by:
Fernando Soto earned 250 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL and CLR parameter strings 9 32
SQL Syntax 6 32
SQL syntax question 6 45
SQL 2012 Instance Problem 3 63
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

730 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