From ServiceControl 7, Error and Audit instances can use SQL Server instead of RavenDB storage. Select SQL Server when an instance should use an existing SQL Server deployment. Storage is configured separately for each instance.
When using SQL Server, Error instances require external message body storage in addition to the database, even when message bodies fit inline. Audit instances start without it, but then do not store large or binary bodies.
Supported SQL Server versions
ServiceControl supports the SQL Server versions that are in mainstream support; see the SQL Server lifecycle. Full-Text Search must be installed; see Prepare the database.
Prepare the database
Create a database before configuring the instance as ServiceControl does not create the database. Setup creates the instance's schema if it does not exist. If the identity that runs setup cannot create schemas, create the schema in advance and grant that identity rights on it. Error and Audit instances can use the same database but not the same schema; see sharing a database.
SQL Server Full-Text Search must be installed on the server. Error and Audit instance setup fail without it. The mcr. container images do not include it; on Linux, including custom container images, install the mssql-server-fts package as described in Install SQL Server Full-Text Search on Linux.
Message body search is always enabled for SQL Server storage, regardless of the EnableFullTextSearchOnBodies setting.
Database permissions
Grant each identity the following rights on the instance's database:
| Identity | Required rights |
|---|---|
| The identity that runs setup | Membership in db_ddladmin, db_datareader, and db_datawriter, or in db_owner. Setup creates the schema, tables, indexes, and the full-text catalog and index, and records the applied migrations. |
| The identity the instance runs as | Membership in db_datareader and db_datawriter, or SELECT, INSERT, UPDATE, and DELETE on the instance's schema. Normal operation does not change the schema. |
When the same connection string is used for setup and normal operation, as the ServiceControl Management Utility and PowerShell do, that identity needs the setup rights.
Authentication
Configure database authentication in the connection string for each Error or Audit instance. This is separate from the transport connection string.
ServiceControl uses Microsoft.. Microsoft Entra ID authentication is supported via the standard connection string options, including managed identity and service principal authentication.
Choose an authentication method suitable for an unattended service. Ensure the selected identity is available to the ServiceControl host and has the database permissions required for setup and normal operation.
Error instance configuration
Set the storage type to SQLServer, provide the database connection string, and configure the retention period. Also configure an external message body store, which is required even if most bodies fit inline in the database. The ServiceControl Management Utility and the PowerShell module configure it when they create the instance. For manual or container deployments, add the ServiceControl/ settings to the instance's configuration file or environment.
ServiceControl/StorageType
Added in version 7.0.0
The storage implementation used by the instance. This setting is required; an instance without it does not start.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_STORAGETYPE |
| App config key | ServiceControl/ |
| SCMU field | STORAGE TYPE |
| Type | Default value |
|---|---|
| string | None (required) |
Valid values are RavenDB, SQLServer, and PostgreSQL. To choose where message bodies are stored with SQL Server or PostgreSQL storage, use ServiceControl/.
ServiceControl/Database/ConnectionString
Added in version 7.0.0
The connection string for the SQL Server or PostgreSQL database. The database must already exist.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_DATABASE_CONNECTIONSTRING |
| App config key | ServiceControl/ |
| SCMU field | DATABASE CONNECTION STRING |
| Type | Default value |
|---|---|
| string | None (required for SQL Server and PostgreSQL storage) |
ServiceControl/Database/Schema
Added in version 7.0.0
The schema that contains the Error instance tables. If the schema does not exist, setup creates it, which requires permission to create schemas. Changing this setting does not move existing data; an instance that already has data must keep using the schema that contains it.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_DATABASE_SCHEMA |
| App config key | ServiceControl/ |
| SCMU field | N/A |
| Type | Default value |
|---|---|
| string | None. Tables are created in the connection's default schema: the login's default schema on SQL Server (usually dbo), or the current schema from search_path on PostgreSQL (usually public). |
ServiceControl/ErrorRetentionPeriod
The grace period that errored messages are kept before they are deleted.
For a message to be considered for deletion, it needs to have a status of either Archived, RetryIssued, or Resolved.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_ERRORRETENTIONPERIOD |
| App config key | ServiceControl/ |
| SCMU field | ERROR RETENTION PERIOD |
| Type | Default value |
|---|---|
| timespan | None (required) (SCMU slider defaults to 15 Days) |
Valid range for this setting is between 5 days and 45 days.
Set these variables in the Error instance's environment to use file system body storage. Replace the connection string placeholder with credentials supplied by the deployment environment. These storage settings supplement the instance's transport and other required settings.
SERVICECONTROL_STORAGETYPE=SQLServer
SERVICECONTROL_DATABASE_CONNECTIONSTRING="Server=sqlserver;Database=ServiceControl;User Id=sc;Password=..."
SERVICECONTROL_MESSAGEBODY_STORAGETYPE=FileSystem
SERVICECONTROL_MESSAGEBODY_FILESYSTEM_STORAGEPATH=/var/servicecontrol/bodies
SERVICECONTROL_ERRORRETENTIONPERIOD=15
See the Error instance settings reference for the complete reference.
To share the ingestion load across several processes, see Scaling out error ingestion. Workers use this instance's database, schema, and message body store, and only this instance runs setup.
Audit instance configuration
Set the storage type to SQLServer, provide the database connection string, and configure the retention period. Also configure an external message body store, which is required even if most bodies fit inline in the database. The ServiceControl Management Utility and the PowerShell module configure it when they create the instance. For manual or container deployments, add the ServiceControl. settings to the instance's configuration file or environment.
ServiceControl.Audit/StorageType
Added in version 7.0.0
The storage implementation used by the Audit instance. This setting is required; an instance without it does not start.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_AUDIT_STORAGETYPE |
| App config key | ServiceControl. |
| SCMU field | STORAGE TYPE |
| Type | Default value |
|---|---|
| string | None (required) |
Valid values are RavenDB, SQLServer, and PostgreSQL. To choose where message bodies are stored with SQL Server or PostgreSQL storage, use ServiceControl..
ServiceControl.Audit/Database/ConnectionString
Added in version 7.0.0
The connection string for the SQL Server or PostgreSQL database. The database must already exist.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_AUDIT_DATABASE_CONNECTIONSTRING |
| App config key | ServiceControl. |
| SCMU field | DATABASE CONNECTION STRING |
| Type | Default value |
|---|---|
| string | None (required for SQL Server and PostgreSQL storage) |
ServiceControl.Audit/Database/Schema
Added in version 7.0.0
The schema that contains the Audit instance tables. If the schema does not exist, setup creates it, which requires permission to create schemas. Changing this setting does not move existing data; an instance that already has data must keep using the schema that contains it.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_AUDIT_DATABASE_SCHEMA |
| App config key | ServiceControl. |
| SCMU field | N/A |
| Type | Default value |
|---|---|
| string | sc_audit |
ServiceControl.Audit/AuditRetentionPeriod
The grace period to keep an audit message before it is deleted.
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_AUDIT_AUDITRETENTIONPERIOD |
| App config key | ServiceControl. |
| SCMU field | AUDIT RETENTION PERIOD |
| Type | Default value |
|---|---|
| timespan | None (required) |
Valid range for this setting is from 1 hour to 365 days.
With PostgreSQL storage, the retention period must be between 1 and 90 days. ServiceControl does not start with a period outside that range. SQL Server storage uses the general range above.
ServiceControl.Audit/MaxBodySizeToStore
A size limit, in bytes, for message bodies. Its effect depends on the storage type:
| Storage | Effect |
|---|---|
| RavenDB | The largest message body that the Audit instance stores. Larger bodies cannot be viewed in ServicePulse. |
| SQL Server or PostgreSQL | The largest text message body that is stored inline in the database. Larger text bodies, and bodies that are not text, are stored in the external message body store and can be viewed in ServicePulse. A larger text body also keeps its first MaxBodySizeToStore bytes in the database for full-text search. See what is stored where. |
| Context | Name |
|---|---|
| Environment variable | SERVICECONTROL_AUDIT_MAXBODYSIZETOSTORE |
| App config key | ServiceControl. |
| SCMU field | N/A |
| Type | Default value |
|---|---|
| int | 102400 (100 KB) |
SQL Server and PostgreSQL storage do not support maintenance mode. An instance with MaintenanceMode set to true does not start.
Example environment variables for an Audit instance using file system body storage:
SERVICECONTROL_AUDIT_STORAGETYPE=SQLServer
SERVICECONTROL_AUDIT_DATABASE_CONNECTIONSTRING="Server=sqlserver;Database=ServiceControl.Audit;User Id=sc;Password=..."
SERVICECONTROL_AUDIT_MESSAGEBODY_STORAGETYPE=FileSystem
SERVICECONTROL_AUDIT_MESSAGEBODY_FILESYSTEM_STORAGEPATH=/var/servicecontrol/audit-bodies
SERVICECONTROL_AUDIT_AUDITRETENTIONPERIOD=30
See the Audit instance settings reference for the complete reference.
Run setup
Run the instance setup process (--setup) before first use and after every upgrade. Setup applies the database migrations; the instance does not apply them at startup.
Setup applies database migrations for both Error and Audit instances. Setup also provisions the external message body store. See database permissions for the rights setup and normal operation need. See the Error container setup or Audit container setup instructions when deploying in containers.
The ServiceControl Management Utility (SCMU) and the PowerShell module run setup when they create or upgrade an instance, and can create SQL Server-backed Error and Audit instances:
- SCMU: choose
SQL Serveras the STORAGE TYPE, enter the DATABASE CONNECTION STRING, and check the MESSAGE BODY PATH, which defaults to%ProgramData%\. SCMU stores message bodies only on the file system.Particular\ ServiceControl\ <instance name>\ MessageBodies - PowerShell: pass
-StorageType SQLServerand-DatabaseConnectionStringtoNew-ServiceControlInstanceorNew-ServiceControlAuditInstance, and leave out-DBPathand-DatabaseMaintenancePort, which apply only to RavenDB. Also pass-MessageBodyPath, or choose Azure Blob Storage or Amazon S3 with-MessageBodyStorageType. See the Error instance and Audit instance PowerShell guides.
To change the message body store after the instance is created, change the message body settings in the instance's configuration file. Bodies already stored are not moved, so make the change before the instance ingests messages.
Neither tool sets Database/, so instances they create use the default schema. Two Audit instances in one database both use the sc_audit schema, and two Error instances that connect with the same login both use that login's default schema, so they share tables. Create independent instances of the same type in separate databases. To share a database between Audit instances on purpose, see Scaling out audit ingestion; those instances must also share a message body store. An Error instance and an Audit instance can use one database, because their default schemas differ.
Verify the setup
Setup logs SQL Server database migration completed for an Error instance, or Audit database migration completed for an Audit instance, and exits without an error. After the instance starts, check that no storage custom checks report a failure in ServicePulse.
Troubleshooting
- Setup fails with "ServiceControl requires the SQL Server Full-Text Search feature": install Full-Text Search on the server, then run setup again.
- Setup fails with a permission error: grant the rights in database permissions, or create the schema in advance.
- Setup fails because "A primary instance and an audit instance cannot share a schema": set a different
Database/for one of the instances. See sharing a database.Schema - The instance does not start with "Maintenance mode is not supported": set
MaintenanceModetofalse. Maintenance mode is only available with embedded RavenDB storage. To perform database maintenance, stop the ServiceControl instance and access SQL Server directly. - The ServiceControl Retention custom check fails: check the instance log. A body store that refuses deletes stops failed-message retention; see external message body storage operations.
- Messages show without their bodies after a restore: restore the database and the external message body store from the same point in time. See backup and restore.
Next steps
- Choose and configure an external message body store for each instance.
- Plan backup and restore of the database and the message bodies together; RavenDB-specific procedures do not apply.
- To deploy in containers, see the Error instance and Audit instance container guides.