cannot update because of lock

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrDeej
    New Member
    • Apr 2007
    • 157

    cannot update because of lock

    The heading is translated from a error message in norwegian which comes when users are trying to registrer to a table in access using this code:

    Code:
    Function registrere_lokasjonshistorikk(Varenr As String, antall_tabletter As Integer, Fra As String, til As String, Optional Gembaloksum As Long, Optional MudaLoksum As Long, Optional Hendelse As String, Optional Behandlingstype As String, Optional Boksnr As Long, Optional Pakkealternativ As String)
    Init_Globals
    ntlogin = Environ("Username")
    
    Dim rst As New ADODB.Recordset
        rst.Open "SELECT * From [tbl lokasjonsflytthistorikk]", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
        With rst
            .AddNew
            !Varenr = Varenr
            ![antall tabletter] = antall_tabletter
            ![Fra lokasjon] = Fra
            ![til lokasjon] = til
            If Not IsNull(Gembaloksum) Then
            ![Sum Gemba] = Gembaloksum
            End If
            If Not IsNull(MudaLoksum) Then
            ![Sum Muda] = MudaLoksum
            End If
            If Not IsNull(Hendelse) Then
            !Hendelse = Hendelse
            End If
            If Not IsNull(Behandlingstype) Then
            ![Behandlingstype] = Behandlingstype
            End If
            If !autonr = 100000 Then
            MsgBox "*", vbOKOnly, "**"
            End If
            If Not IsNull(Pakkealternativ) Then
            !Pakkealternativ = Pakkealternativ
            End If
            If Not IsNull(Boksnr) Then
            !Boksnr = Boksnr
            End If
            ![rettet av] = ntlogin
            ![Rettet tid] = Now
            .Update
            .Close
        End With
    Set rst = Nothing
    
    
    End Function
    When i try to access the table manually and i try to make a new post i also get the error message

    The code has been working fine for 96 000 rows in the table, but lately when both reading and writing to the table has increased the error message has come from time to time

    The way i solve it is to make a copy of the database and make all the users log on to the copy and then it works fine again

    I also use the code
    Code:
     rst.Open "SELECT * From [tbl lokasjonsflytthistorikk]", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    for different calculating jobs and other things and my first hunch here is that this code somewhat locks the table till it is finished with it's job. Hmm.. I need to fix this quick
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32654

    #2
    It's not clear, but it seems to me you have already found your problem.

    Comment

    • MrDeej
      New Member
      • Apr 2007
      • 157

      #3
      yes... the error havent apperaed the last week :)

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32654

        #4
        Good for you MrD :)

        Comment

        • MrDeej
          New Member
          • Apr 2007
          • 157

          #5
          Ai.. now i got the same error on another table. Does ',adLockOptimis tic' lock the entire table and adLockPessimist ic only locks each active row?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32654

            #6
            I don't think that's how it works.

            Check out LockTypeEnum in the Help system (Type LockTypeEnum then hit F1 - all within the IDE - Alt-F11 from the main application) for a better explanation. It seems to imply Record level locking for both.

            Comment

            Working...