1

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.

zdarsky.peter
  • 6,188
  • 9
  • 39
  • 60

3 Answers3

2

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.

Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87
  • 3
    Meanwhile this file contains the note, that you should not execute it directly, but use aspnet_reqsql.exe as described here: https://msdn.microsoft.com/en-us/library/ms178586%28v=vs.100%29.aspx – Niklas Peter Aug 13 '15 at 15:09
  • I took the script's advice and ran it through the Visual Studio command line instead of running the SQL script directly. For example, to install it on my local machine I used the following line: aspnet_regsql.exe -ssadd -sstype p -S . -E – Justin Mar 11 '21 at 20:56
1

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.

vulcanik
  • 98
  • 1
  • 4
0

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.

bitcoder
  • 1,217
  • 12
  • 22