Walkthrough: Configuring a shared session state database using the SQL provider

Current version: 9.1

A contact can make multiple visits to a website from different devices or browser sessions at the same time. With shared session state the session state database collects all the data that can be shared across these multiple sessions. This includes, for example, data related to contacts and devices. This data is still private to the contact but it is accessible from all current sessions made by the same contact.

You must always configure shared session state on content delivery (CD) servers, regardless of whether you have a single CD server, multiple CD servers, or a clustered environment.

Note

Shared session state is not supported on content management (CM) servers.

You can configure shared session state to use any Session state store provider that extends the abstract SessionStateStoreProviderBase class (shipped with ASP.NET). The only additional requirement is that the Session state store provider must be able to invoke the SessionEnd event using the SessionStateItemExpireCallback delegate.

Note

The standard OutOfProcSessionStateStore class that ships with ASP.NET does not support the SessionEnd event and therefore  you cannot use it with shared session state.

This walkthrough tells you how to use a SQL Server database as your shared Session state store provider using the Sitecore ASP.NET Session state provider for SQL Server. It describes how to:

  • Deploy a SQL Server session database

  • Configure Sitecore

  • Adjust shared session state settings

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.

Note

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

To deploy the SQL Server session database:

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

  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 Deploy Data-tier Application.

  4. In the Deploy Data-tier Application wizard, on the Select Package page, click Browse.

  5. Select the Sitecore.Sessions.dacpac file and click Next

    Note

    You can find the file in the Databases folder in the root of the Sitecore archive.

  6. In the Update Configuration step, specify the name of the database, click Next and, after validating summary information, click  Next. When the deploy is completed, the session database appears in your list of attached databases.

  7. Add the following connection string to the ConnectionStrings.config file:

    RequestResponse
    <add
        name="sharedSession"
        connectionString="User ID=<SQL server username>;Password=<user password>;Data Source=<SQL server>;Database=<shared session database name>"
    />
    
  8. The connection string user must be allowed to execute stored procedures on the session database. No other privileges are necessary. A system administrator can grant this privilege with these SQL statements:

    RequestResponse
    USE <shared session database name>;
    GRANT EXECUTE TO <SQL server username>;
    GO

Configure Sitecore

Note

Do not make changes directly to the configuration files. Instead, you must create a patch file that performs the required changes during run time.

By default, Sitecore uses the in-process provider, which stores data in memory and is implemented in the internal ASP.NET InProcSessionStateStore class:

RequestResponse
<sharedSessionState defaultProvider="inProc">
    <providers>
    <clear/>
    <add name="inProc"
      type="System.Web.SessionState.InProcSessionStateStore"
      />
    </providers>

To configure Sitecore to use the shared Session state store provider for SQL Server instead of the default:

  1. In your website root folder, navigate to the \App_Config\Sitecore\Marketing.Tracking folder.

  2. Open the Sitecore.Analytics.Tracking.Config file.

  3. Locate the line where you can define the default shared Session state provider using the following path: sitecore/tracking/sharedSessionState.

  4. Change the default provider from inProc to mssql and change the name attribute value to mssql.

    RequestResponse
    <sharedSessionState
          defaultProvider="mssql">
        <providers>
            <clear/>
            <add name="mssql"
                type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider,Sitecore.SessionProvider.Sql"
                connectionStringName="sharedsession"
                pollingInterval="2"
                compression="true"
                sessionType="shared"/>
        </providers>
Note

You can store shared and private session state information in the same database. The database is able to distinguish between the types of session.

Adjust shared session state settings

In the Sitecore.Analytics.Tracking.Config file, edit the following session state settings:

Setting

Description

Value

connectionStringName

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

Edit to specify the session state database that you want.

For example:

connectionStringName="sharedSession"

pollingInterval

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

For example:

pollingInterval="2"

compression

Specifies 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 can cause some additional CPU overhead.

For example:

compression="true"

sessionType

Specifies that the type of session state is shared.

Only valid value:

sessionType="shared"

Do you have some feedback for us?

If you have suggestions for improving this article,