Solved

Using NOLOCK with MS ACCESS 97 (or 2000)

Posted on 2003-11-04
6
1,052 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access, How to create variable 9 35
Clear Current Value from Combobox 2 24
MS Access How can I complete my Max, Group by query? 13 22
Hide shared folder for some users 2 24
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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