Results 1 to 13 of 13

Thread: [RESOLVED -FINALLY :-) ] could not update; currently locked

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    [RESOLVED -FINALLY :-) ] could not update; currently locked

    I have this intermittent error (could not update; currently locked). Occuring intermittently in a database write loop at random locations.

    This has me pulling my hair out as it only happens intermittently (more on larger databases) and at RANDOM locations in the loop ... even when nothing changes from run to run.

    This happens on many different computers and many different database files.

    Any help greatly appreciated!

    The database is an mdb file on the same drive as the app.
    error occurs at random update statements.
    There is NO multiuser access ... only the single access.
    PSUEDOCODE follows:
    VB Code:
    1. Dim rst As New ADODB.Recordset
    2.     Dim rst2 As New ADODB.Recordset
    3.     Dim rst3 As New ADODB.Recordset
    4.     Dim rst4 As New ADODB.Recordset
    5.  
    6.         strTemp = "SELECT * FROM aa WHERE bb = 1"
    7.         rst.Open strTemp, cnn, adOpenDynamic, adLockOptimistic
    8.        
    9.        
    10.         strTemp = "SELECT * FROM cc WHERE dd = 1"
    11.         rst2.Open strTemp, cnn, adOpenDynamic, adLockOptimistic
    12.        
    13.  
    14.         strTemp = "SELECT * FROM ee WHERE ff = 1"
    15.         rst3.Open strTemp, cnn, adOpenDynamic, adLockOptimistic
    16.        
    17.  
    18.         strTemp = "SELECT * FROM gg WHERE hh = 1"
    19.         rst4.Open strTemp, cnn, adOpenDynamic, adLockOptimistic
    20.  
    21. for i = 1 to 1000
    22.     rst2.AddNew
    23.     rst2!aaaa = bbbb
    24.     rst2.Update
    25.  
    26.     rst3.AddNew
    27.     rst3.Fields("cccc") = dddd
    28.     rst3.Update
    29.  
    30.     rst4.AddNew
    31.     rst4.Fields("eeee") = ffff
    32.     rst4.Update
    33.  
    34.     rst.AddNew
    35.     rst.Fields("gggg") = hhhh
    36.     rst.Update
    37. next i
    38.  
    39.     rst.Close
    40.     rst2.Close
    41.     rst3.Close
    42.     rst4.Close
    43.    
    44.     Set rst = Nothing
    45.     Set rst2 = Nothing
    46.     Set rst3 = Nothing
    47.     Set rst4 = Nothing
    Last edited by Muddy; Apr 2nd, 2007 at 10:24 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: could not update; currently locked

    One method to avoid it would be to wait for the update to complete, eg;
    VB Code:
    1. rst2.Update
    2. Do While rst2.adStateExecuting
    3.   DoEvents
    4. Loop
    ..alternatively, you could use a different method to add the data to the database - see the "how do I add a record" article in the database FAQ's.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    Quote Originally Posted by si_the_geek
    One method to avoid it would be to wait for the update to complete, eg;
    VB Code:
    1. rst2.Update
    2. Do While rst2.adStateExecuting
    3.   DoEvents
    4. Loop
    ..alternatively, you could use a different method to add the data to the database - see the "how do I add a record" article in the database FAQ's.
    Thanks Si, but that doesnt pop up on intellisense for me. I typed it in anyway and it did correct the case of the letters in adStateExecuting, but when I try to run it I get "Method or Data Member not found"

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    OK changed your code to :
    rst2.Update
    Do While rst2.status = adStateExecuting
    DoEvents
    Loop

    and it runs, but I still get the error. The value of rst2.status when the problem occurs is 16 ... I dont want to just hardwire the 16 in without understanding what that means .... I assume it is adStateSomething AND adStateSomethingElse.

    almost there ..... any ideas?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    OK, strange development. It seems to be working now (thought its fooled me before). I changed the code to the following .... but WHY does it work? isnt status=0 closed? what's going on?

    heres what I replaced my updates with:
    VB Code:
    1. Do While rst2.Status > 0
    2.                     DoEvents
    3.                 Loop
    4.                 rst2.Update
    5.                 Do While rst2.Status > 0
    6.                     DoEvents
    7.                 Loop
    8.                 frmStatus.Caption = "Saving"
    Last edited by Muddy; Dec 12th, 2006 at 01:09 PM.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    ok, it fooled me again ... its still broke.

    here's the deal:

    I dont call rst.update until rst.status <= 0
    on calling update I get the "locked" error
    on debugging the error the rst.status value is 16

    help .... please ....

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    OK, assuming it's not fooling me again, I think Ive got it. This is pretty old code that was behaving well on older hardware and smaller databases. On a larger database on a Core Duo it consistently crashed as described, though.

    I noticed that the reference was set to "Microsoft Data Access Components 2.7" .... I cleared this reference and set it to "Microsoft Data Access Components 2.8" and so far it is behaving perfectly.

    Ill give it some time and post back here for the benefit of others who may run into this issue.

    Thanks!

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: could not update; currently locked

    Doh! Yep, I made a big blunder on my copy & paste (that'll teach me to use VB to verify code I post!!), you almost got what I meant tho.

    Rather than Status (which is per record, with different values than adStateExecuting etc) you should be using State (which is for the whole recordset).


    The switch to MDAC 2.8 may well be a valid solution - I'm afraid I dont know what changed from 2.7 to 2.8, but support for multi-core processors is certainly a possibility.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    errors are back even trying everything mentioned so far in this thread ...

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: could not update; currently locked

    Oh dear...

    Have you tried one of the other methods in the "how do I add a record" FAQ?

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    Quote Originally Posted by si_the_geek
    Oh dear...

    Have you tried one of the other methods in the "how do I add a record" FAQ?
    Thanks ... Ill try that (didnt notice it before).

    Right now I have switched from Early binding to Late binding and it seems to be working ... for now ...

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    problem still there no matter early or late bound

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: could not update; currently locked

    It appears that I have finally resolved this issue with the following open method (for all 4 open statements):

    rst.Open strTemp, cnn, adOpenDynamic, adLockPessimistic, adCmdTableDirect

    I won't claim to understand exactly why ... but is does seem to be working. I post for the benefit of future searchers.

    Thanks to everyone who replied!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width