Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 826387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:24:27+00:00 2026-05-15T03:24:27+00:00

Is the ASP.NET 4.0 SQL session state mechanism backward-compatible with the ASP.NET 2.0 schema

  • 0

Is the ASP.NET 4.0 SQL session state mechanism backward-compatible with the ASP.NET 2.0 schema for session state, or should/must we create a separate and distinct session state database for our ASP.NET 4.0 apps?

I’m leaning towards the latter anyway, but the 2.0 database seems to just work, though I’m wondering if there are any substantive differences between the ASPState database schema / procedures between the 2.0 and 4.0 versions of ASP.NET. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:24:28+00:00Added an answer on May 15, 2026 at 3:24 am

    There was no quick answer on this from anybody, so I did some digging. I generated an ASPState database using the aspnet_regsql.exe tool from .NET 2.0, and then I did the same thing using the same tool but from .NET 4.0. Then, I generated scripts from each of those resulting SQL Server databases and used a comparison tool to isolate the differences.

    What I found is: The only material difference between the ASPState schema from .NET 2.0 to .NET 4.0 versions is the dbo.DeleteExpiredSessions stored procedure. That’s the stored procedure called periodically by a SQL Server Agent scheduled job also installed by the tool.

    Consequently, it would seem that the schema for ASPState 2.0 and ASPState 4.0 are perfectly compatible and so it’s not necessary, from a technical standpoint, to segregate ASP.NET 2.0 and ASP.NET 4.0 session state – but I’ll likely do it anyway.

    (This finding was a bit surprising, as ASPState changed a lot from .NET 1.1 to .NET 2.0.)

    Details for each version’s changed stored proc:

    .NET 2.0 ASPState DeleteExpiredSessions stored procedure:

    CREATE PROCEDURE dbo.DeleteExpiredSessions
    AS
        DECLARE @now datetime
        SET @now = GETUTCDATE()
    
        DELETE [ASPState].dbo.ASPStateTempSessions
        WHERE Expires < @now
    
        RETURN 0   
    GO
    

    .NET 4.0 ASPState DeleteExpiredSessions stored procedure:

    CREATE PROCEDURE dbo.DeleteExpiredSessions
    AS
        SET NOCOUNT ON
        SET DEADLOCK_PRIORITY LOW 
        DECLARE @now datetime
        SET @now = GETUTCDATE() 
        CREATE TABLE #tblExpiredSessions 
        ( 
            SessionID nvarchar(88) NOT NULL PRIMARY KEY
        )
        INSERT #tblExpiredSessions (SessionID)
            SELECT SessionID
            FROM [ASPState].dbo.ASPStateTempSessions WITH (READUNCOMMITTED)
            WHERE Expires < @now
        IF @@ROWCOUNT <> 0 
        BEGIN 
            DECLARE ExpiredSessionCursor CURSOR LOCAL FORWARD_ONLY READ_ONLY
            FOR SELECT SessionID FROM #tblExpiredSessions 
            DECLARE @SessionID nvarchar(88)
            OPEN ExpiredSessionCursor
            FETCH NEXT FROM ExpiredSessionCursor INTO @SessionID
            WHILE @@FETCH_STATUS = 0 
                BEGIN
                    DELETE FROM [ASPState].dbo.ASPStateTempSessions WHERE
                        SessionID = @SessionID AND Expires < @now
                    FETCH NEXT FROM ExpiredSessionCursor INTO @SessionID
                END
            CLOSE ExpiredSessionCursor
            DEALLOCATE ExpiredSessionCursor
        END 
        DROP TABLE #tblExpiredSessions
    RETURN 0     
    GO
    

    As for why the above change was necessary, I found the following MSDN blog post:

    • Deadlock when storing Asp.net sessions in SQL server during peak load

    Excerpt, in reference to the older procedure:

    …
    This would take the locks on all
    the expired records for deletion and
    these locks may be promoted to page
    locks. This can give rise to deadlocks
    with other ‘session state write
    statements’ when the number of records
    marked for deletion increases. By
    default this stored procedure is
    supposed to run every minute.
    …

    Consequently, the newer version of the stored proc may be advisable for ASP.NET 2.0 apps, too.

    One more thing I learned from the blog post that I did not know: ASP.NET 4.0 session state mechanism now offers compression. Search on compressionEnabled at sessionState Element (ASP.NET Settings Schema).


    Finally, I also just found something relevant from Microsoft, at ASP.NET Side-by-Side Execution Overview. Excerpt:

    …
    If SQL Server is used to manage
    session state, all versions of ASP.NET
    (of the .NET Framework) that are
    installed on the same computer can
    share the SQL state server that is
    installed with the latest version of
    ASP.NET. The schema for session state
    is the same in all versions of
    ASP.NET.

    (Though there are some differences in implementation not specific to the schema.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.