Solved

Expert Topic: what locking do you use?

Posted on 2011-02-22
5
362 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help Required 3 97
SQL - Copy data from one database to another 6 19
SQL2016 to ORACLE11G linked-server 6 15
syntax sql error 2 13
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

777 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