---
title: "Walkthrough: Configuring a shared session state database using the SQL provider"
slug: "walkthrough--configuring-a-shared-session-state-database-using-the-sql-provider"
abstract: "How to use the SQL service provider as your private session state store."
---
# Walkthrough: Configuring a shared session state database using the SQL provider

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](https://doc.sitecore.com/xp/en/developers/91/platform-administration-and-architecture/scaling-and-configuring-session-state.html "Scaling and configuring session state") 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

<details>
<summary><h2>Deploy a SQL Server session database</h2></summary>

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:

    ```xml
    <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:

    ```

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

</details>

<details>
<summary><h2>Configure Sitecore</h2></summary>

> [!note]
> Do not make changes directly to the configuration files. Instead, you must create a [patch file](https://doc.sitecore.com/xp/en/developers/91/platform-administration-and-architecture/use-a-patch-file-to-customize-the-sitecore-configuration.html "Use a patch file to customize the Sitecore configuration") 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:

```xml
<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`.

    ```xml
    <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.

</details>

<details>
<summary><h2>Adjust shared session state settings</h2></summary>

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.<br><br>Edit to specify the session state database that you want. | For example:<br><br>`connectionStringName="sharedSession"` |
| `pollingInterval` | Specifies the time interval in seconds that the session-state provider uses to check if any sessions have expired. | For example:<br><br>`pollingInterval="2"` |
| `compression` | Specifies that you want session state data to be compressed.<br><br>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:<br><br>`compression="true"` |
| `sessionType` | Specifies that the type of session state is `shared`. | Only valid value:<br><br>`sessionType="shared"` |

</details>