我正在倾向于后者,但2.0数据库似乎只是工作,虽然我想知道ASP.NET 2.0和4.0版本之间的ASPState数据库模式/过程之间是否存在实质性差异.谢谢.
解决方法
我发现是:从.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
> 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.
(虽然在实现方面有一些不同于模式的特定区别.)