Solved

Expert Topic: what locking do you use?

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

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 68

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 68

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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, show how to shrink a transaction log file down to a reasonable size.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now