AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/persistence/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

SQL Azure

NuGet Package:
NServiceBus.NHibernate 9.x
Target Version:
NServiceBus 8.x
Standard support for version 8.x of NServiceBus has expired. For more information see our Support Policy.

NHibernate persistence works with SQL Azure without needing to make any changes to code or configuration. However, there are considerations that should be taken into account when using a remote database.

Relational database as a service

When using a relational database as a service for persisting NServiceBus data, it is important to keep in mind that this type of data store has different runtime semantics than a traditional relational database.

  • The data store is potentially located in a remote location and is thus subject to a broad range of potential networking issues.
  • 'As a service' environments such as SQL Azure are typically shared environments, so performance of the database can be impacted by the behavior of other databases on the server.

The combination of these characteristics means that any transaction executed against the database may show intermittent exceptions. Usually these exceptions are transient in nature and can be resolved by retrying the transaction. A good place to start is the Transient Fault Handling documentation from Microsoft.

Handling transient failures

Message processing that fails because of a transient database error is retried by recoverability.

To reduce failures caused by dropped connections, add ConnectRetryCount and ConnectRetryInterval to the connection string. These settings control connection retries and the reconnection of idle connections that were broken. See Troubleshoot transient connection errors in Azure SQL for details and defaults.

SQL Azure driver

On .NET Framework, the community-maintained NHibernate.SqlAzure driver can be used instead. The driver uses the Microsoft Transient Fault Handling library to retry failed SQL Azure connections. The package targets .NET Framework 4.5 and has not been updated since 2020.

There are two choices of package for this library:

After installation of the package, enable the driver by setting the NHibernate connection.driver_class property:

var nhConfiguration = new Configuration
{
    Properties =
    {
        ["connection.driver_class"] = "NHibernate.SqlAzure.SqlAzureClientDriver, NHibernate.SqlAzure"
    }
};

var persistence = endpointConfiguration.UsePersistence<NHibernatePersistence>();
persistence.UseConfiguration(nhConfiguration);

Related Articles