Configuring ASP session state on SQL server

This is a brief to the point note on how to setup ASP session state to use SQL server to store session information.

  1. Open Visual Studio CMD and run the following command.
    For SQL Server with Windows Authentication Security:

    aspnet_regsql -S 'serverName' -E -ssadd -sstype p

    For SQL Server with SQL Security:

    aspnet_regsql -S 'serverName' -U 'UserName' -P 'Password' -ssadd -sstype p

    1
    This command will create the ASP Session State tables in the SQL Server. You will find in the figure above that i have used ‘.’ in the ServerName as i am pointing to the Local SQL Server on my machine.
    If you don’t have visual studio CMD you can still open the normal CMD and navigate to the .net framework “Cd ‘C:\WINDOWS\Microsoft.NET\Framework\v4.XXX’ ” then use the aspnet_regsql

  2. Now after having our tables ready we need to reconfigure our web.config to change the session mode to SQLServer.
    For SQL Server with Windows Authentication Security:

    <sessionstate mode="SQLServer" timeout="20" allowcustomsqldatabase="true" 
    sqlconnectionstring="Data Source=Server;Integrated-Security=SSPI;" cookieless="false">

    For SQL Server with SQL Security:

    <sessionstate mode="SQLServer" timeout="20" allowcustomsqldatabase="true" 
    sqlconnectionstring="Data Source=Server;User ID=UserID;Password=Password;" 
    cookieless="false">

That’s it, Now you have your ASP session stored in you SQL server 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s