Question

I am using InProc mode of SessionState, but my app is keep restarting because of the recycling of application pool so I am loosing session of currently logged in users. I want to change to save it in database. I edited my webconfig like this

<sessionState mode="SQLServer" timeout="20" allowCustomSqlDatabase="true"
    sqlConnectionString="Data Source=Server;integrated security=True;Initial Catalog=SerialTracker;"
    cookieless="false" />

Do I have to create some tables for session state or new database ? My hosting is shared so I can not acces to admin console or anything else.

Was it helpful?

Solution

There is a step by step HowTo available here. Seems you will be needing to run a SQL file named InstallSqlState.sql on the database.

OTHER TIPS

Yes, you have to use the InstallSqlState.sql script that you can find - according to the machine - in %System Drive Letter%/Microsoft .NET/Framework/%v.????%

Example: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallSqlState.sql

Consider also that the script create a AspState DB who will not keep, by default, session data: these will be stored in tempdb table.

If these is not good for you there's the way to save data inside the AspState DB, take a look here.

As of 2015, you don't need to run a script, the Universal Provider package uses Entity Framework to create the table it needs.

I used NuGet/Package Manager to install the 'Microsoft ASP.NET Universal Providers' package (currently v 2.0.0) which also installs the Core:

Install-Package Microsoft.AspNet.Providers

It inserts some (commented) items in your web.config file. I followed the instructions in the comment to change 'InProc' to 'Custom' and set it up with the connection string to my database. On first run it creates a 'Sessions' table in my database and stores the session data in there.

I'm not sure what it would do if you already had a 'Sessions' table in your project.

ps - I removed the 'profile', 'membership', and 'rolemanager' tags it inserted, as I only need to store the session stuff, not the rest of asp identity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top