how to save website sessions to ms sql database for websites

If you are planing to use a load balancer, websites sessions may create some problems if load balancer does not support session management. In this case you can save the sessions to a ms sql database and fix the issue.  It’s simple to save session to database. You will need to create a database using the aspnet_regsql command.

Step1: Take CMD as administrator and go to the Dotnet framework folder

Step2: Use the command ‘aspnet_regsql -ssadd -sstype c -d SessionDatabase –E’

This will create a database called SessionDatabase. You can Create user and allow DBO permission through studio manager as you create normal database users.

Step3:  Updated your web.config with following values

<sessionState mode=”SQLServer” allowCustomSqlDatabase=”true” sqlConnectionString=”data source=SQL-SERVER-NAME;Initial Catalog=SessionDatabase;User ID=DATABASE-USER;Password=DATABASE-PASSWORD;” cookieless=”false” timeout=”120″ />