Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1099
  • Last Modified:

Using NOLOCK with MS ACCESS 97 (or 2000)

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
Treaty_Frum
Asked:
Treaty_Frum
  • 2
  • 2
  • 2
1 Solution
 
peter57rCommented:
Could you use an ADO recordset instead?
You could close the connection thereby releasing locksand then work on the recordset independently.

Pete
0
 
stevbeCommented:
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
 
Treaty_FrumAuthor Commented:
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
stevbeCommented:
sorry I missed that part ... looks like Pete's suggestion is the way to go.
0
 
Treaty_FrumAuthor Commented:
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
 
peter57rCommented:
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 SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now