加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

是否有必要创建ASP.NET 4.0 SQL会话状态数据库,与现有的ASP.NET

发布时间:2020-12-15 23:54:13 所属栏目:asp.Net 来源:网络整理
导读:ASP.NET 4.0 SQL会话状态机制是否与会话状态的ASP.NET 2.0架构向后兼容,或者/我们应该/我们必须为我们的ASP.NET 4.0应用程序创建一个单独的和不同的会话状态数据库? 我正在倾向于后者,但2.0数据库似乎只是工作,虽然我想知道ASP.NET 2.0和4.0版本之间的ASPSt
ASP.NET 4.0 SQL会话状态机制是否与会话状态的ASP.NET 2.0架构向后兼容,或者/我们应该/我们必须为我们的ASP.NET 4.0应用程序创建一个单独的和不同的会话状态数据库?

我正在倾向于后者,但2.0数据库似乎只是工作,虽然我想知道ASP.NET 2.0和4.0版本之间的ASPState数据库模式/过程之间是否存在实质性差异.谢谢.

解决方法

没有任何人快速回答,所以我做了一些挖掘.我使用.NET 2.0中的aspnet_regsql.exe工具生成了一个ASPState数据库,然后我使用相同的工具,但是从.NET 4.0做了同样的事情.然后,我从每个生成的SQL Server数据库生成脚本,并使用比较工具来隔离差异.

我发现是:从.NET 2.0到.NET 4.0版本的ASPState架构之间唯一的重大区别是dbo.DeleteExpiredSessions存储过程.这是由工具也安装的SQL Server代理程序作业定期执行的存储过程.

因此,似乎ASPState 2.0和ASPState 4.0的架构是完全兼容的,因此从技术角度来看,不需要分离ASP.NET 2.0和ASP.NET 4.0会话状态 – 但是我也可能会这样做.

(这个发现有点令人惊讶,因为ASPState从.NET 1.1变化到.NET 2.0)

每个版本的更改存储过程的详细信息:

.NET 2.0 ASPState DeleteExpiredSessions存储过程:

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存储过程:

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

至于为什么上述变化是必要的,我发现以下MSDN博客文章:

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

摘录,参考较旧的程序:


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.

因此,存储过程的较新版本也可能适用于ASP.NET 2.0应用程序.

我从博客中学到的另一件事我不知道:ASP.NET 4.0会话状态机制现在提供压缩.在sessionState Element (ASP.NET Settings Schema)上搜索compressionEnabled.

最后,我还刚刚在ASP.NET Side-by-Side Execution Overview发现了一些与微软有关的内容.摘录:


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.

(虽然在实现方面有一些不同于模式的特定区别.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读