Add this as a stored procedure to the ASPState database:
CREATE PROCEDURE [dbo].[DeleteExpiredSessions] AS DECLARE @now datetime SET @now = GETUTCDATE() DELETE [ASPState].dbo.ASPStateTempSessions WHERE Expires < @now RETURN 0
Then add the task to the SQL Server agent, which runs at regular intervals (my start-up works at midnight), which performs the next step in this database:
dbo.DeleteExpiredSessions
This ensures that when sessions expire, they leave, even if the process that created them does not exist. If you want to get rid of them all when you restart your process, just do a:
DELETE [ASPState].dbo.ASPStatsTempSessions
This will delete all sessions in the database.
source share