Solved

Expert Topic: what locking do you use?

Posted on 2011-02-22
5
400 Views
Last Modified: 2012-05-11
Following the example of http:Q_26838925.html :

This discussion is intended for Experts working with SQL Server , and is focused on locking and cursors.

In your development, do you use anything other than client-based cursors?
Do you regularly use transactions?
If you do, how do you achieve it in the development tools?

This thread is publicly visible.
0
Comment
Question by:Vadim Rapp
[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
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 34953800
We use (VS) C++ and ADO with server-based cursors (forward-only and static). It can be assumed forward-only runs as client-based cursor.

Transactions are opened by switching the transaction isolation level of the connection from "read uncommitted" or "read committed" to "repeatable read". Repeatable read prevents updates on read records.
0
 
LVL 40

Author Comment

by:Vadim Rapp
ID: 34953933
What is user B wants to update a record locked by user A who just has left for lunch?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 34953976
NEVER let a transaction open for longer than a few seconds. If you read records to present them in a GUI, or require any other user interaction, you do that without locking. As soon as you want to update, you either need to check yourself if the record (or specific value) has been changed meanwhile, or force-update, loosing all changes performed by other users.

BTW, sure you only want to spend 50 points here?
0
 
LVL 40

Author Comment

by:Vadim Rapp
ID: 34954078
If I'm not mistaken, this is pretty much how client-based cursor works. When it uploads the data, it of course does place some locks anyways.

Re. 50 points - as I posted in the 1st post, it's an inter-expert discussion, for those who are interested. It's not that anybody needs an assistance in resolving a problem.
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 50 total points
ID: 34954382
You are correct with the client-based cursor - at least in part. The cursor might still do (forward) paging, and hence locking the records of the page actually worked on.

And no - it does not work that way. A client-cursor needs to be considered as a read-snapshot. In a fully integrated GUI solution, like a datagrid, only the current record is locked (if at all). Changing the row will save.
Another approach used with ADO.Net is that you have the (paged) snapshot, and it is automatically managing locking and updating when you call another page. But that works only reliably with server-based cursors.
0

Featured Post

Technology Partners: 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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

617 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