Asp.Net 4.0存储会话中的SqlServer [英] Asp.Net 4.0 Storing Session in SqlServer
问题描述
我必须通过共享主机提供的数据库。我想存储在SQL服务器的会话,但它给我的错误:
I Have Database provided by shared hosting. I want to store the session in sql server but it give me error:
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包括下面的语句。
My WebConfig include Following Statement.
<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
。
I have run aspnet_regsql.exe
. It asked me about the server and login detail after that it created aspNret_TableNames
.
请指引我。
推荐答案
我相信你一定已经使用了aspnet_regsql.exe的应用程序,然后开始一个向导,然后添加各种aspnet_的 * 的表,你的表
I believe you must have used the aspnet_regsql.exe application which then starts a wizard and then adds various aspnet_* tables to your tables.
如果这样,再次重启相同的向导,然后选择删除选项,从数据库中删除所有这些表。
If so then again restart the same wizard and then choose the remove option to remove all those tables from the database.
现在运行这个命令:
aspnet_regsql.exe -ssadd -d <Your Database> -sstype c -S <Server> -U <Username> -P <Password>
这会再添加两个表到数据库,即ASPStateTempApplications&安培; ASPStateTempSessions。
This will then add two tables to your database, namely ASPStateTempApplications & ASPStateTempSessions.
修改你的web.config文件以包括以下配置:
Modify your web.config file to include the following configuration:
<sessionState
mode="SQLServer"
allowCustomSqlDatabase="true"
sqlConnectionString="Data Source=Server;Initial Catalog=Database;User ID=UserId;Password=Password"
cookieless="false" timeout="20" />
请注意:
1.我假设你想你的应用程序数据库中存储会话。如果要单独维护会话数据库则没有-D参数运行上面的命令。这将创建一个新的数据库ASPState的与我在上面已经指定了两个表。最后,你可以指定该数据库中配置的名称。
NOTE: 1. I have assumed that you want to store session within your applications database. If you want to maintain the session database separately then run the above command without the "-d" parameter. This will create a new ASPState database with two table that I have specified above. And finally you can specify the name of this database in your configuration.
希望这有助于:)
这篇关于Asp.Net 4.0存储会话中的SqlServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!