Solved

Using NOLOCK with MS ACCESS 97 (or 2000)

Posted on 2003-11-04
6
1,011 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

747 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

10 Experts available now in Live!

Get 1:1 Help Now