Solved

Using NOLOCK with MS ACCESS 97 (or 2000)

Posted on 2003-11-04
6
1,057 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

751 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