Solved

Using NOLOCK with MS ACCESS 97 (or 2000)

Posted on 2003-11-04
6
1,066 Views
Last Modified: 2008-02-01
Help! I'm suspecting that NOLOCK doesn't work in either Access 97 or Access 2000 (either that or it can't be used for ODBC databases?). Trying to access an ODBC database table without locking the fields (I thought creating a select-type recordset wouldn't lock things up, but alas, I'm apparently still locking up some tables)

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * from dbo_ITEM_INVENTORY_6MO_SALES " & _
    "WHERE (((dbo_ITEM_INVENTORY_6MO_SALES.CORP_CODE)='10'));")

I was hoping to use:
Set rs = CurrentDb.OpenRecordset("SELECT * from dbo_ITEM_INVENTORY_6MO_SALES (NOLOCK) " & _
    "WHERE (((dbo_ITEM_INVENTORY_6MO_SALES.CORP_CODE)='10'));")

NOLOCK doesn't seem to work in my MS Access module ("Syntax Error in From Clause") Anyone have any experience with this?
0
Comment
Question by:Treaty_Frum
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 9679170
Could you use an ADO recordset instead?
You could close the connection thereby releasing locksand then work on the recordset independently.

Pete
0
 
LVL 39

Expert Comment

by:stevbe
ID: 9680161
have you tried setting the lockedits argument to dbOptimistic so it will only lock when processing an "Update"

Set rs = CurrentDb.OpenRecordset("SELECT * from dbo_ITEM_INVENTORY_6MO_SALES " & _
    "WHERE (((dbo_ITEM_INVENTORY_6MO_SALES.CORP_CODE)='10'));", , , dbOptimistic )

Steve
0
 

Author Comment

by:Treaty_Frum
ID: 9680353
Not even sure if that one will do it. Found this text in the helpfile:
"When working with Microsoft Jet-connected ODBC data sources, the LockEdits property is always set to False, or optimistic locking. The Microsoft Jet database engine has no control over the locking mechanisms used in external database servers".
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 39

Expert Comment

by:stevbe
ID: 9680432
sorry I missed that part ... looks like Pete's suggestion is the way to go.
0
 

Author Comment

by:Treaty_Frum
ID: 9689172
For some reason, I wasn't able to close the ADO connection and continue muddling about with the recordset. Here's what I tried:

cnt.Open "Provider=MSDASQL.1; ..."
rs.Open "SELECT ...;", cnt, adOpenForwardOnly, adLockReadOnly
cnt.close
do until rs.eof
        ...
        rs.movenext
loop
<ERROR OCCURS WHEN I TRY TO ACCESS THE RECORDSET>

For now, I've just crossed my fingers that the adOpenForwardOnly, adLockReadOnly properties will still allow others to update the table even if I'm in it (i.e. no locking). (Unless there are other ideas!)

Final code:
Dim cnt As New ADODB.Connection
Dim rs As New ADODB.Recordset

cnt.ConnectionTimeout = 0
cnt.CommandTimeout = 0
cnt.CursorLocation = adUseClient
cnt.Mode = adModeRead

cnt.Open "Provider=MSDASQL.1; ..."
rs.Open "SELECT ...;", cnt, adOpenForwardOnly, adLockReadOnly
0
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 9689934
The basic code for a disconnected recordset is:

Dim rs as ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockBatchOptimistic
rs.Open "Select * From mytable", "DSN=mydsn"
Set rs.ActiveConnection = Nothing

If you want something that you could do in A97 then I guess you could simply copy the table locally or to a temp mdb file and process the records from there.  You would have to update the main table on a record by record basis using SQL Update statements, but it would release the main table.

Pete
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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