Skip to main content

SQL Server

SQL Server supports both the Master database and Agent transport layers.

Install

dotnet add package JobMaster.SqlServer

Configuration

builder.Services.AddJobMasterCluster(config =>
{
config.ClusterId("My-Cluster")
.UseSqlServerForMaster("Server=...;Database=...;User Id=...;Password=...;TrustServerCertificate=True;");

config.AddAgentConnectionConfig("SqlServer-1")
.UseSqlServerForAgent("Server=...;Database=...;User Id=...;Password=...;TrustServerCertificate=True;");
});

Options

Table prefix

By default, JobMaster creates tables with the JM_ prefix. Override it via the tablePrefix parameter on UseSqlServerForMaster/UseSqlServerForAgent:

config.UseSqlServerForMaster("Server=...;Database=...;User Id=...;Password=...;TrustServerCertificate=True;", tablePrefix: "myapp_jm_");

config.AddAgentConnectionConfig("SqlServer-1")
.UseSqlServerForAgent("Server=...;Database=...;User Id=...;Password=...;TrustServerCertificate=True;", tablePrefix: "myapp_agent_");

Also available through ConfigFromJson's connectionOptions: {"tablePrefix": "myapp_jm_"}.

Migrating from UseSqlTablePrefixForMaster/UseSqlTablePrefixForAgent

Those generic methods are now [Obsolete] — they applied regardless of which provider a connection actually used, which didn't make much sense (e.g. calling UseSqlTablePrefixForMaster on a RavenDB-master cluster). They still compile and behave the same; migrate to the tablePrefix parameter above at your convenience.

Disable auto schema provisioning

By default, JobMaster creates and migrates its tables on startup. Disable this if you manage schema migrations yourself:

config.UseSqlServerForMaster("...")
.DisableAutoProvisionSqlSchema();

JobMaster's database reads always use the READ COMMITTED isolation level. On SQL Server, that isolation level uses shared locks by default, so readers and writers can block each other under concurrent load. Enabling READ_COMMITTED_SNAPSHOT (RCSI) makes readers use row versioning instead, avoiding that contention without changing any JobMaster configuration:

ALTER DATABASE [YourDatabaseName] SET READ_COMMITTED_SNAPSHOT ON;

Run this once against your JobMaster database — it requires no other active connections at the moment it runs, so treat it like a brief maintenance-window operation on a production database. Not required, but recommended for any cluster under meaningful concurrent load.