How to store and access sessions in the database

asp.net, c#, database, session, sql-server

Solution

You can find all configuration details on this MSDN article. Go to section `SQL Server Mode`

This is the required configuration

<configuration>
  <system.web>
    <sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/>
  </system.web>
</configuration>

Here you have some details about where the session information is stored and how to change the default location. For more details, check this article as Andre Calil suggested.

By default, the Aspnet_regsql.exe tool will create a database named ASPState containing stored procedures that support SQLServer mode. Session data itself is stored in the tempdb database by default. You can optionally use the -sstype option to change the storage location of session data

Problem

I'm doing an advanced project with ASP .NET Sessions, I would like to know: A) What do I add exactly to my web.config to enable full session writing to the database server. B) What table would the sessions be stored in once enabled? So far I'm only aware that the default is "TempDB".

Original source