Monday, January 21, 2013

asp.net Session State SQL Server Setup

On a  recent project I needed to add a SQLServer to manage my asp.net session state.  I could not find a single easy source on how to do this so here it is below.

Steps
1. Go to C:\Windows\Microsoft.NET\Framework64\v4.0.30319 on a command line
2. Paste and run - aspnet_regsql –ssremove –E -S .  this will remove the state server that is installed.  I have used this when I need to start over because my state server was not installed correctly.
3. Paste and run - aspnet_regsql.exe -S .\ -E -ssadd -sstype p
-S .\  This is the server name, in this case it uses the default server instance.  This works great for dev local setup, but you will need a real sql server name for deployments.
-sstype p don't put anything in the tempdb on the sql server, keep it all in the state database you are creating
-ssadd flag to create the tables, this exe can be used for membership provider pattern and other stuff, so make sure you only want to add the state server stuff.

4. In your web.config add
<sessionState mode="SQLServer" timeout="180" allowCustomSqlDatabase="true" sqlConnectionString="Data Source=.\;Initial Catalog=ASPState;Integrated Security=True"/>


No comments:

Post a Comment