Sql-server – How to clear SQL session state for all users in ASP.NET

asp.netsessionsession-statesql server

I use SQLServer SessionState mode to store session in my ASP.NET application. It stores certain objects that are serialized/deserialized every time they are used.

If I make any changes in code of the structure of those objects and I put a new version live, any logged user will get an error, as their session objects (the old version ones) do not match the structure that the new version expects while deserializing.

Is there a way to clear all sessions at once in DB so that all active sessions expire and users are forced to log in again (and therefore all session objects are created from scratch)?

Or… Is there any other way to solve this situation?

Best Answer

You may try using stored procedure in SQL Server to clear all the sessions:

CREATE PROCEDURE [dbo].[DeleteSessions]
AS
DELETE [ASPState].dbo.ASPStateTempSessions

RETURN 0