Solved

Expert Topic: what locking do you use?

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Format Date fields 11 65
CAST issue with SQL 2000 15 44
How do i delete the last node in an xml in T-SQL 7 29
how to use ROW_NUMBER() correctly 8 44
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

710 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