session state - custom mode RRS feed

  • Question

  • User121086535 posted

    I created a class that is inheriting the SessionStateStoreProviderBase class
    I do not quite understand the whole point of locking
    I copied an example of implementation of the code as Microsoft Write
    There's a method that I did not quite understand it, there seemed that the update command will never excute

    becouse locked 2 is alweys false

    If lockRecord Then
                    cmd = New SqlCommand("UPDATE Sessions SET Locked = @Locked1, LockDate = @LockDate WHERE SessionId = @SessionId AND ApplicationName = @ApplicationName AND Locked = @Locked2 AND Expires > @Expires", conn)
                    cmd.Parameters.AddWithValue("@Locked1", True)
                    cmd.Parameters.AddWithValue("@LockDate", DateTime.Now)
                    cmd.Parameters.AddWithValue("@SessionId", id)
                    cmd.Parameters.AddWithValue("@ApplicationName", ApplicationName)
                    cmd.Parameters.AddWithValue("@Locked2", False)
                    cmd.Parameters.AddWithValue("@Expires", DateTime.Now)

                    If cmd.ExecuteNonQuery() = 0 Then
                        ' No record was updated because the record was locked or not found.
                        locked = True
                        ' The record was updated.
                        locked = False
                    End If
                End If





    Monday, August 22, 2011 4:17 PM


  • User699558600 posted

    No it true or false based on which method calls it

    see here 

     Public Overrides Function GetItemExclusive(context As HttpContext, _
          id As String, _
          ByRef locked As Boolean, _
          ByRef lockAge As TimeSpan, _
          ByRef lockId As Object, _
          ByRef actionFlags As SessionStateActions) _
          As SessionStateStoreData 
          Return GetSessionStoreItem(True, context, id, locked, lockAge, lockId, actionFlags)
        End Function

    Here the call to GetSessionStoreItem passed 1st parameter as True which makes lockRecord  True


    lockRecord is True when called from GetItemExclusive and False when called from GetItem

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 23, 2011 5:50 AM