2

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

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"/>

I have run aspnet_regsql.exe. It asked me about the server and login detail after that it created aspNret_TableNames.

Please guide me.

1 Answer 1

13

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.

Now run this command:

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

This will then add two tables to your database, namely ASPStateTempApplications & ASPStateTempSessions.

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" />

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.

Hope this helps :)

Sign up to request clarification or add additional context in comments.

4 Comments

I had dropped using it now i will give a try to your solution
Hey Demon, great solution :))
How we can do that on a web host when we don't have access the server environment?
Hi Mohammad Sanati, I think your service provider should help you with this. Normally they do have the expertise to handle such situations. If not then may be you will have to provide them detailed steps to get things done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.