【问题标题】:Asp.Net 4.0 Storing Session in SqlServerAsp.Net 4.0 在 SqlServer 中存储会话
【发布时间】:2014-02-12 21:55:24
【问题描述】:

我有共享主机提供的数据库。我想将会话存储在 sql server 中,但它给了我错误:

Unable to use SQL Server because ASP.NET version 2.0 Session State is not installed on the SQL server. Please install ASP.NET Session State SQL Server version 2.0 or above

[HttpException (0x80004005): Unable to use SQL Server because ASP.NET version 2.0 Session State is not installed on the SQL server. Please install ASP.NET Session State SQL Server version 2.0 or above.]
System.Web.SessionState.SqlPartitionInfo.GetServerSupportOptions(SqlConnection sqlConnection) +2147087
System.Web.SessionState.SqlPartitionInfo.InitSqlInfo(SqlConnection sqlConnection) +107
System.Web.SessionState.SqlStateConnection..ctor(SqlPartitionInfo sqlPartitionInfo, TimeSpan retryInterval) +531
System.Web.SessionState.SqlSessionStateStore.GetConnection(String id, Boolean& usePooling) +237
System.Web.SessionState.SqlSessionStateStore.CreateUninitializedItem(HttpContext context, String id, Int32 timeout) +136
System.Web.SessionState.SessionStateModule.CreateUninitializedSessionState() +50
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +659
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +96
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

我的 WebConfig 包含以下声明。

    <sessionState mode="SQLServer"
      cookieless="true"
      regenerateExpiredSessionId="true"
      timeout="30"
      allowCustomSqlDatabase="true"
      sqlConnectionString="Data Source=hostingServer;Initial         catalog=MyDatabase;User Id=MyUser;password=MyPassword;"
      stateNetworkTimeout="60"/>

我已经运行aspnet_regsql.exe。它在创建aspNret_TableNames 之后询问了我有关服务器和登录详细信息。

请指导我。

【问题讨论】:

    标签: asp.net sql-server-2008 session-state


    【解决方案1】:

    我相信您一定使用过 aspnet_regsql.exe 应用程序,该应用程序会启动一个向导,然后将各种 aspnet_* 表添加到您的表中。

    如果是这样,请再次重新启动同一向导,然后选择删除选项以从数据库中删除所有这些表。

    现在运行这个命令:

    aspnet_regsql.exe -ssadd -d <Your Database> -sstype c -S <Server> -U <Username> -P <Password>
    

    这会将两个表添加到您的数据库中,即 ASPStateTempApplications 和 ASPStateTempSessions。

    修改您的 web.config 文件以包含以下配置:

    <sessionState
        mode="SQLServer"
        allowCustomSqlDatabase="true"
        sqlConnectionString="Data Source=Server;Initial Catalog=Database;User ID=UserId;Password=Password"
        cookieless="false" timeout="20" />
    

    注意: 1. 我假设您希望将会话存储在您的应用程序数据库中。如果要单独维护会话数据库,则运行上面的命令,不带“-d”参数。这将创建一个新的 ASPState 数据库,其中包含我在上面指定的两个表。最后,您可以在配置中指定此数据库的名称。

    希望这会有所帮助:)

    【讨论】:

    • 我已经放弃使用它了,我会试试你的解决方案
    • 嘿,恶魔,很好的解决方案 :))
    • 当我们无法访问服务器环境时,如何在虚拟主机上做到这一点?
    • 您好 Mohammad Sanati,我认为您的服务提供商应该帮助您解决这个问题。通常,他们确实具有处理此类情况的专业知识。如果没有,那么您可能必须向他们提供完成工作的详细步骤。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 2012-02-12
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多