How to enable ASP.NET SQL Server Session on your web application

SQLServer mode stores session state in a SQL Server database. Using this mode ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm. 

To use SQLServer mode, you must first be sure the ASP.NET state service is running on the server used for the session store.

The ASP.NET SQL Server registration tool (Aspnet_regsql.exe) is used to create a Microsoft SQL Server database that is used by the SQL Server providers in ASP.NET. The tool is also used to add or remove options from an existing database. Regardless of what version of the .NET Framework you are working with, the Aspnet_regsql.exe file is located in the following folder on the Web server computer: [drive:]\%windir%\Microsoft.NET\Framework\v2.0.50727 You can run Aspnet_regsql.exe without any command-line arguments to run a wizard that will walk you through specifying connection information for your SQL Server installation, and installing or removing the database elements for the membership, role management, profile, Web Parts personalization, and health monitoring features.To configure an ASP.NET application to use SQLServer mode, do the following in the application's Web.config file:

Set the mode attribute of the sessionState element to SQLServer.

Set the sqlConnectionString attribute to a connection string for your SQL Server database.

Note :
To improve the security of your application when using SQLServer mode, it is recommended that you protect your sqlConnectionString value by encrypting the sessionState section of your configuration file.  

The following example shows a configuration setting for SQLServer mode where session state is stored on a SQL Server named "SampleSqlServer":

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

Was this answer helpful?

 Print this Article

Also Read

Can I run multiple ASP.NET Frameworks on different directories on my website?

No. Multiple versions of the ASP.NET Framework cannot run on a single website. The selected .NET...

There is three types of ASP.Net sessions :

1)Inprocess session   (it's stored by default in web.cofig File and use for same...

How to configure your website for using Ajax (for Windows 2008 Hosting Plans)

Note:  If you want to use ASP.Net "Integrated PipeLine" version (under any circumstance) you...

I get a configuration error when I execute my ASP.NET 2.0 web application.

DETAILSI get the following error when I try to execute my application. Parser Error Message:...

Sample Code : Connecting to a MySQL database with ASP using a DSN-less connection

  Here is the connection string, you can use to connect to a MySQL database with ASP :...