Solved

Expert Topic: what locking do you use?

Posted on 2011-02-22
5
372 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
  • 3
  • 2
5 Comments
 
LVL 69

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 69

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 69

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

820 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