Cannot insert duplicate key in object 'dbo.SessionState' error in log


Description

An unhandled exception might occur when sending two or more requests with the same session cookie at exactly the same time, for example, when reopening the same site in two different tabs in the just-closed browser after the session has expired. This issue is specific to the SQL session state provider and it is not reproducible with other providers. You can see the following messages in the logs:

ERROR Application error.
Exception: System.Data.SqlClient.SqlException
Message: Violation of PRIMARY KEY constraint 'PK_SessionState'. Cannot insert duplicate key in object 'dbo.SessionState'. The duplicate key value is (ii1lixtzzj2zmli03rzmyj0x, a61578e7-9cef-4246-a657-668e7f0dffd7).
The statement has been terminated.
Source: .Net SqlClient Data Provider
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
...

Solution

To resolve this issue, consider one of the following options: