Using SQL Server for ASP.Net session state
idunno.org/articles/277.aspx
Improving ASP.NET Session State database performance by reducing blocking
msmvps.com/blogs/greglow/archive/2007/02/04/improving-asp-net-session-state-database-performance-by-reducing-blocking.aspx#544414
CREATE PROCEDURE dbo.DeleteExpiredSessions
AS
DECLARE @now datetime
SET @now = GETUTCDATE()
CREATE TABLE #ExpiredSessions
( SessionID nvarchar(88) NOT NULL
PRIMARY KEY
)
INSERT #ExpiredSessions (SessionID)
SELECT SessionID
FROM [ASPState_2_0].dbo.ASPStateTempSessions
WHERE Expires < @now
DECLARE SessionCursor CURSOR LOCAL FORWARD_ONLY READ_ONLY
FOR SELECT SessionID FROM #ExpiredSessions ORDER BY CHECKSUM(NEWID())
DECLARE @SessionID nvarchar(88)
OPEN SessionCursor
FETCH NEXT FROM SessionCursor INTO @SessionID
WHILE @@FETCH_STATUS = 0 BEGIN
DELETE FROM [ASPState_2_0].dbo.ASPStateTempSessions
WHERE SessionID = @SessionID
FETCH NEXT FROM SessionCursor INTO @SessionID
END
CLOSE SessionCursor
DEALLOCATE SessionCursor
DROP TABLE #ExpiredSessions
RETURN 0
GO
-- 25/02/2009 11:56:46: post edited by sergey.