Getting Started
Architecture
NServiceBus
Transports
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

SQL Persistence Upgrade Version 2 to 3

Component: Sql Persistence

Accessing business data

When accessing business data in Versions 2 and below, the SQL persistence session information was injected into the storage session state irrespective of the selected storage type. In Versions 3 and above, the SQL persistence session information will only be injected if the SQL persistence is used for either Sagas or the Outbox. If the SQL persistence is for one of those and another persistence is used for the other, then an exception will be thrown. For example, it is not possible to mix SQL persistence for Sagas with any other persistence for Outbox. The same applies for the inverse.

Variant renamed to Dialect

To more accurately reflect SQL vernacular "Variant" has been renamed to "Dialect":

// For Sql Persistence version 3.x
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.SqlDialect<SqlDialect.MySql>();

// For Sql Persistence version 2.x
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.SqlVariant(SqlVariant.MySql);

The SqlDialect method returns a typed settings instance that can be used to apply configuration specific to that dialect:

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var mySqlDialectSettings = persistence.SqlDialect<SqlDialect.MySql>();

Dialect selection made mandatory

Versions 2 and below defaulted to SQL Server when a call to SqlVariant was omitted. In Versions 3 and above a call to SqlDialect is mandatory.

Schema moved to SqlDialect

Schema configuration has been moved to extend the result of the SqlDialect method:

// For Sql Persistence version 3.x
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var dialect = persistence.SqlDialect<SqlDialect.MsSqlServer>();
dialect.Schema("MySchema");

// For Sql Persistence version 2.x
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.Schema("MySchema");