是否有必要创建与现有 ASP.NET 2.0 ASPState DB 不同的 ASP.NET 4.0 SQL 会话状态数据库?

发布于 2024-09-02 20:47:42 字数 220 浏览 4 评论 0 原文

ASP.NET 4.0 SQL 会话状态机制是否向后兼容 ASP.NET 2.0 会话状态架构,或者我们应该/必须为 ASP.NET 4.0 创建一个单独且不同的会话状态数据库应用程序?

无论如何,我倾向于后者,但 2.0 数据库似乎可以正常工作,尽管我想知道 2.0 和 4.0 版本之间的 ASPState 数据库架构/过程之间是否存在任何实质性差异ASP.NET。谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谢绝鈎搭 2024-09-09 20:47:42

任何人都没有对此做出快速回答,所以我做了一些挖掘。我使用 .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 博客文章:

摘录,参考旧过程:

...
这将锁定所有
需要删除的过期记录
这些锁可能会提升到页面
锁。这可能会导致死锁
与其他'会话状态写入
报表'时的记录数
标记为删除增加。经过
默认这个存储过程是
应该每分钟运行一次。
...

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

我从博客文章中了解到另一件事我不知道:ASP.NET 4.0 会话状态机制现在提供压缩。在 compressionEnabled ="nofollow noreferrer">sessionState 元素(ASP.NET 设置架构)


最后,我还刚刚在 ASP.NET 并行执行概述。摘抄:

...
如果使用SQL Server来管理
会话状态,所有版本的 ASP.NET
(.NET Framework 的)
安装在同一台电脑上即可
共享 SQL 状态服务器
安装了最新版本的
ASP.NET。 会话状态的架构
在所有版本中都是相同的
ASP.NET。

(尽管在实现上存在一些差异,但不特定于架构。)

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:

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文