L
londonboy
Guest
Hi. I'm having trouble getting record locking to work between an Access front-end and a SQL database. After reading a number of web posts, I found the relevant options to the Recordset.Open command to obtain the type of locking I want, however I now have a hanging Recordset.Find command.
The code sample is below:
-------------------------
Private Sub FindRecord()
Dim cnConnx as ADODB.Connection
Dim rsDetails as ADODB.Recordset
set cnConnx = New ADODB.Connection
set rsDetails = New ADODB.Recordset
cnConnx.Open "Driver={SQL Server};Server=srv;Database=db;Uid=user;Pwd=pass;"
cnConnx.CommandTimeout = 5
rsDetails.Open "Table", cnConnx, adOpenDynamic, adLockPessimistic, adCmdTableDirect
On Error GoTo RecordLocked
rsDetails.Find "Username = 'User'", 0, adSearchForward
....
-------------------------
Everything works fine for the first user of the system, they get the data they want and can edit it. However, if a second user comes along and tries to edit the same record, the system hangs until user1 performs a Recordset.Update or Recordset.Close. The CommandTimeout is being ignored and the system never returns to the user.
I can't use adLockOptimistic as this doesn't give me the control the system requires. I have also tried using adCmdTable but this locks the whole table rather than just the found record!
Can anyone shed any light on this?
Thanks.
The code sample is below:
-------------------------
Private Sub FindRecord()
Dim cnConnx as ADODB.Connection
Dim rsDetails as ADODB.Recordset
set cnConnx = New ADODB.Connection
set rsDetails = New ADODB.Recordset
cnConnx.Open "Driver={SQL Server};Server=srv;Database=db;Uid=user;Pwd=pass;"
cnConnx.CommandTimeout = 5
rsDetails.Open "Table", cnConnx, adOpenDynamic, adLockPessimistic, adCmdTableDirect
On Error GoTo RecordLocked
rsDetails.Find "Username = 'User'", 0, adSearchForward
....
-------------------------
Everything works fine for the first user of the system, they get the data they want and can edit it. However, if a second user comes along and tries to edit the same record, the system hangs until user1 performs a Recordset.Update or Recordset.Close. The CommandTimeout is being ignored and the system never returns to the user.
I can't use adLockOptimistic as this doesn't give me the control the system requires. I have also tried using adCmdTable but this locks the whole table rather than just the found record!
Can anyone shed any light on this?
Thanks.