Db2.HealthChecks integrates IBM Db2 probes with Microsoft.Extensions.Diagnostics.HealthChecks.
The package is designed to be portable and enterprise-friendly: it does not hard-code an OS-specific IBM driver dependency. Instead, it creates connections through an explicit connection factory, an ADO.NET DbProviderFactory, or the IBM Db2 provider loaded by the consuming application.
- ASP.NET Core / Worker Service health check integration.
- Default lightweight Db2 query:
SELECT 1 FROM SYSIBM.SYSDUMMY1. - Custom probe query support.
- Configurable timeout and command timeout.
- Configurable failure status and tags.
- Connection-string,
DbProviderFactory, or DI-friendlyDbConnectionfactory setup. - Logging through
Microsoft.Extensions.Loggingwhen logging is registered. - Multi-target package:
netstandard2.0,net8.0, andnet10.0. - SourceLink and deterministic build metadata for NuGet consumers.
The library itself is OS-independent. The actual runtime support depends on the IBM Db2 ADO.NET provider used by your application.
Typical provider packages:
| OS | Provider package |
|---|---|
| Windows | Net.IBM.Data.Db2 |
| Linux | Net.IBM.Data.Db2-lnx |
Note: the IBM provider must be installed by the consuming application. This avoids producing NuGet packages whose dependencies change depending on the OS used to pack the library.
When using Net.IBM.Data.Db2-lnx, the IBM native client also needs Linux shared libraries available at runtime. On Debian/Ubuntu-based images this typically means:
apt-get update && apt-get install -y libxml2 libaio1t64The IBM package copies clidriver next to your build output. If libdb2.so is not found, ensure the clidriver/lib directory is visible to the process, for example via LD_LIBRARY_PATH in containerized workloads.
Install this package and the appropriate IBM provider package for your deployment OS.
builder.Services.AddHealthChecks()
.AddDb2Check(
name: "db2",
connectionString: builder.Configuration.GetConnectionString("Db2")!,
tags: new[] { "db", "db2", "ready" },
timeout: TimeSpan.FromSeconds(5),
commandTimeoutSeconds: 3);Use the options overload for enterprise scenarios such as dynamic secrets, Key Vault integration, custom connection creation, or non-default failure status.
builder.Services.AddHealthChecks()
.AddDb2Check("db2", options =>
{
options.ConnectionString = builder.Configuration.GetConnectionString("Db2")!;
options.Query = "SELECT 1 FROM SYSIBM.SYSDUMMY1";
options.Timeout = TimeSpan.FromSeconds(5);
options.CommandTimeoutSeconds = 3;
options.FailureStatus = HealthStatus.Degraded;
options.Tags = new[] { "db", "db2", "critical" };
});builder.Services.AddHealthChecks()
.AddDb2Check("db2", options =>
{
options.ConnectionFactory = serviceProvider =>
{
var connectionString = serviceProvider
.GetRequiredService<IConfiguration>()
.GetConnectionString("Db2")!;
// Requires the IBM provider package in the consuming application.
return new IBM.Data.Db2.DB2Connection(connectionString);
};
});builder.Services.AddHealthChecks()
.AddDb2Check("db2", options =>
{
options.ProviderFactory = IBM.Data.Db2.DB2Factory.Instance;
options.ConnectionString = builder.Configuration.GetConnectionString("Db2")!;
});Recommended pattern:
/health/live: process liveness only, no database dependency./health/ready: includes Db2 readiness check, internal/private endpoint.
Example:
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
Predicate = registration => registration.Tags.Contains("ready")
});Avoid exposing detailed health check output publicly. If needed, set:
options.IncludeExceptionDetails = false;netstandard2.0target: supports factory/reflection-based connection creation.DbProviderFactories.GetFactoryis only used on targets where it is available.net8.0andnet10.0targets: supportDbProviderFactories.GetFactorywithProviderInvariantNameas well as explicit factories.- A
DbConnectionreturned byConnectionFactoryis disposed after every check by default. SetDisposeConnection = falseonly when returning an externally owned connection. IncludeExceptionDetailsdefaults tofalse; enable it only on protected diagnostics endpoints.
The library deliberately does not bundle an IBM Db2 driver. Install the provider selected by the
consuming application, such as Net.IBM.Data.Db2 on Windows or Net.IBM.Data.Db2-lnx on Linux.
The provider can be registered with DbProviderFactories, supplied through ProviderFactory, or
used by a custom ConnectionFactory. This keeps IBM driver versions, native dependencies, and
licensing under application control.
dotnet restore
dotnet build
dotnet test
dotnet pack src/Db2.HealthChecks/Db2.HealthChecks.csproj -c ReleaseDo not log or expose Db2 connection strings. See SECURITY.md for vulnerability reporting.