≡ Menu
Deep in the Code

Storing Session State for an ASP.NET Site in a SQL Server Database

When using session state in an ASP.NET Web application, you have several options.

If you want to store it in your application database, as opposed to the ASPstate database (created at the command line with “aspnet_regsql -S [server] -E -ssadd -sstype c -d ASPstate”), I have scripted the database objects and stored them in GitHub at this address:


Replace the name of the database throughout the ASPstate.sql file with your application database name and run against the database. After that, the web.config of your Web application must have the appropriate information added:

 <sessionState mode="SQLServer"
 sqlConnectionString="Integrated Security=SSPI;data
 source=SampleSqlServer;" />

(sqlConnectionString must be set to your database with respective authentication information.)

About the author: I solve problems. Solutions Architect / Senior Software Engineer / Business Analyst / Full-Stack Developer / IT Generalist