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

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

Houston, TX 77002

Leave a Reply