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 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.
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.
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.
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:
-
Start Microsoft SQL Server Management Studio 2016 or later.
-
Connect to the server node that you want to install the Session database on.
-
Expand the server node, right-click Databases, and then click Deploy Data-tier Application.
-
In the Deploy Data-tier Application wizard, on the Select Package page, click Browse.
-
Select the
Sitecore.Sessions.dacpac
file and click Next.NoteYou can find the file in the Databases folder in the root of the Sitecore archive.
-
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.
-
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>" />
-
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:
RequestResponseUSE <shared session database name>; GRANT EXECUTE TO <SQL server username>; GO
Configure Sitecore
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:
<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:
-
In your website root folder, navigate to the
\App_Config\Sitecore\Marketing.Tracking
folder. -
Open the
Sitecore.Analytics.Tracking.Config
file. -
Locate the line where you can define the default shared Session state provider using the following path:
sitecore/tracking/sharedSessionState
. -
Change the default provider from
inProc
tomssql
and change the name attribute value tomssql
.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>
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 |
---|---|---|
|
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:
|
|
Specifies the time interval in seconds that the session-state provider uses to check if any sessions have expired. |
For example:
|
|
Specifies that you want session state data to be compressed. The default value is |
For example:
|
|
Specifies that the type of session state is |
Only valid value:
|