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:

https://github.com/DeepInTheCode/ASPstate

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:

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

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

Houston, TX 77002

Leave a Reply