Walkthrough: Configuring a private session state database using the SQL Server provider

Last updated Friday, April 6, 2018 in Sitecore Experience Platform for Administrator, Developer

In private session state, all data related to a specific interaction, such as viewed pages, converted goals, triggered campaigns, or accumulated engagement points, is collected and saved to the session state database.

This topic outlines how to configure a SQL Server database as your private session state store using the Sitecore ASP.NET Session State Provider for SQL Server:

The SQL Server provider supports the session-end event that is required by the xDB in order to track website visits.

Deploy a SQL Server session database

The Sitecore ASP.NET Session State Provider for SQL Server enables you to use SQL Server as your session state store. This provider supports the SessionEnd event that the xDB needs to track website visits.

To deploy the SQL Server session database:

  1. Start Microsoft SQL Server Management Studio 2012 or later.


    If you are using SQL Server 2008, you first need to download Microsoft SQL Server Management Studio Express before you can deploy the Session database.

  2. Connect to the server node that you want to install the Session database on.
  3. Expand the server node, right-click Databases, and then click Attach.
  4. In the Attach Databases dialog box, click Add.
  5. Browse to the Databases folder in your website root folder, select the Sitecore.Sessions.mdf database and click OK.
  6. In the Attach Databases dialog box, click OK. The session database now appears in your list of attached databases.
  7. Add the following connection string to the ConnectionStrings.config file:
    <add name="session" connectionString="user id=_sql_server_user_;password=_user_password_;Data 
    Source=_sqlserver_;Database = _session_database_name_"/>


You can store shared and private session state info in the same database. The database will have the capacity to distinguish between the types of session.

Optimize SQL Server performance

For each web request, the session-state store database is accessed multiple times. This can have a significant impact on the performance of your website. Therefore, you should install enough RAM to allow Microsoft SQL Server to keep the session state database in memory. You should also put the database files on an SSD drive.

To achieve optimal performance, you can install an extension to the Sessions database.

To install the performance enhancements:

  1. In Microsoft SQL Server Management Studio 2012, open the Sessions db performance boost.sql file.

    This file is stored in the \Databases\Scripts folder of your Sitecore installation.

  2. In the first line of the Sessions db performance boost.sql file, replace USE [Sitecore_Session] with the name of your session database.
  3. After you have updated the USE statement to point to your session database, press F5 to execute the file.


These performance enhancements move the session-state store to SQL Server tempDB which is the standard practice recommended by Microsoft. Please note that the tempdb system database is currently not supported by Azure SQL Database service.

Every user must therefore have access to tempDB. However, every time that SQL Server is restarted, it recreates tempDB and resets the access rights. For information about how to ensure that users always have access to tempDB, see this KB article.

For more information see Session-State Modes on MSDN.

Configure Sitecore

To configure Sitecore to use the private session state provider for SQL Server:

  1. In your site root folder, open the web.config file and locate the sessionState section:
    <sessionState mode="Custom" customProvider="mssql" cookieless="false" timeout="20">
  2. Update the sessionState section by adding the SQL Server provider as shown in the following example. Also, change the name attribute value to mssql:
    <sessionState mode="Custom" customProvider="mssql" cookieless="false" timeout="20">
        <add name="mssql"
             type=" Sitecore.SessionProvider.Sql.SqlSessionStateProvider,

Adjust session state settings

In Sitecore, when you configure a session state, you have the following configuration options:




Contains the connection string that Sitecore uses to connect to the session database.

Edit to specify the session state database that you want to use. In the xDB, this database is called session.

For example:



Specifies the time interval in seconds that the session-state provider uses to check if any sessions have expired.

For example:



Indicates that you want session-state data to be compressed.

The default value is true. Compressing session state data reduces the amount of data that you need to transfer between the database and the Sitecore instance. This may cause some additional CPU overhead.

For example:

compression="true" />


Indicates whether the type of session state is private or shared.

For example:


Send feedback about the documentation to docsite@sitecore.net.