Solved

Record vs Table locking in SQL Server

Posted on 2007-12-06
7
650 Views
Last Modified: 2013-11-28
We are using Access 2007 as a front end and MS SQL Server as a back end. We experienced a locking error. How can we be sure that bound forms in Access are not locking more than the record being worked with?
0
Comment
Question by:VoodooFrog
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
lahousden earned 500 total points
Comment Utility
You can't be sure of that - in fact with Access you can be pretty sure that the reverse is true.  If you are running into concurrency problems (and especially if you have more than one or two users wanting to access the data concurrently) then it is time to move away from access to an enterprise-ready front-end technology, such as ASP.NET, C# or even (dare I say it?) VB.NET.
0
 

Author Comment

by:VoodooFrog
Comment Utility
So would the Jet engine lock many records in the SQL table, or possibly the whole table?
0
 
LVL 10

Assisted Solution

by:lahousden
lahousden earned 500 total points
Comment Utility
I am not sufficiently knowledgable in Jet and Access to know whether it is the Jet engine itself or MS-Access' use of it that is responsible, but our experience with Access front-ends is that they cause too many locks to be held for too long - whether this is because of page or table locks (or simply too many rowlocks) I cannot say...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:VoodooFrog
Comment Utility
How would we go about controlling the locking directly in SQL -- even if we were not using Access?  is there a way to direct SQL server to lock only single records (or page) vs the whole table when accessing it?  
0
 
LVL 10

Assisted Solution

by:lahousden
lahousden earned 500 total points
Comment Utility
There are a couple of locking hints you can use if you are running into concurrency problems.  One is "with (rowlock)" and the other is "with (nolock)".  Look into the use of the "with (nolock)" hint for tables that hardly ever change, such as dimension or static lookup tables, particularly when querying them for drop-down lists or reporting.  You should be careful, however, using the hint on transactional tables that come under any kind of steady modification load, since the hint can result in "dirty reads".  The "with (rowlock)" hint, on the other hand, is totally safe and may improve concurrency in situations where you know you are dealing with small numbers (or small percentages) of rows from a table.  SQL will always obey a legal use of "with (nolock)" but I think it sometimes ignores "with (rowlock)" and goes for page or table locks if it believes it truly knows better.
We have been migrating our applications away from MS-Access front-ends for the last 6 or 7 years - to VB at the outset and more recently to VB.NET and ASP.NET - so it is a long time since I have really encountered the behaviours of MS-Access and their implications on concurrency first-hand.  But as I recall, MS-Access would do things like hold locks on the current table while it was waiting for user input! - and not always only on the particular row that was being displayed!  Needless to say this is a disastrous strategy for systems where any reasonable level of concurrent access is needed.  
0
 

Author Comment

by:VoodooFrog
Comment Utility
where do we get at the with (rowlock)" hint?  I am not sure I follow what you are saying in this.  
0
 
LVL 10

Assisted Solution

by:lahousden
lahousden earned 500 total points
Comment Utility
You include the hints in your SQL statements. E.g., for "with (rowlock)":

Select c.*
from Clients as c with (rowlock)
where c.ClientID = 2034

And for the "with (nolock)" hint:

select i.*, t.TypeName
from invoices as i with (rowlock)
join invoice_type as t with (nolock) on t.InvTypeID = i.InvTypeID
where i.ClientID = 2034

here we are expecting the Invoice_Type table to remain pretty much unchanged all the time, so we can dismiss locking against it for this query.

Note the hint comes after the table alias (if present) and before the join condition (if present).
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 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

16 Experts available now in Live!

Get 1:1 Help Now