Pinqponq.Database.Mssql
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package Pinqponq.Database.Mssql --version 1.0.0
NuGet\Install-Package Pinqponq.Database.Mssql -Version 1.0.0
<PackageReference Include="Pinqponq.Database.Mssql" Version="1.0.0" />
<PackageVersion Include="Pinqponq.Database.Mssql" Version="1.0.0" />
<PackageReference Include="Pinqponq.Database.Mssql" />
paket add Pinqponq.Database.Mssql --version 1.0.0
#r "nuget: Pinqponq.Database.Mssql, 1.0.0"
#:package Pinqponq.Database.Mssql@1.0.0
#addin nuget:?package=Pinqponq.Database.Mssql&version=1.0.0
#tool nuget:?package=Pinqponq.Database.Mssql&version=1.0.0
Pinqponq.Database.Mssql
A minimal SQL Server connection layer for .NET: a retrying connection factory
(ISqlConnectionFactory) built on Microsoft.Data.SqlClient, plus a
ready-made health check. Same shape as Pinqponq.Database.Postgres — it
opens connections with transient-fault classification and stops there. No
repository base classes, no entity mapping.
Install
dotnet add package Pinqponq.Database.Mssql
Requirements
- .NET SDK:
net8.0,net9.0, ornet10.0 - A reachable SQL Server instance (or Azure SQL)
Microsoft.Data.SqlClient(pulled in transitively)
Quick start
using Pinqponq.Database.Mssql;
using Pinqponq.Database.Mssql.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPinqponqMssql(mssql =>
{
mssql.ConnectionString = builder.Configuration.GetConnectionString("Mssql")!;
mssql.RetryCount = 3;
mssql.RetryBaseDelay = TimeSpan.FromMilliseconds(200);
});
builder.Services.AddHealthChecks().AddPinqponqMssql();
var app = builder.Build();
app.MapGet("/version", async (ISqlConnectionFactory factory, CancellationToken ct) =>
{
await using var connection = await factory.OpenConnectionAsync(ct);
await using var command = connection.CreateCommand();
command.CommandText = "SELECT @@VERSION";
return await command.ExecuteScalarAsync(ct);
});
app.Run();
Using the factory from an injected service:
public sealed class ReportRepository(ISqlConnectionFactory factory)
{
public async Task<int> CountOrdersAsync(CancellationToken ct)
{
await using var connection = await factory.OpenConnectionAsync(ct);
await using var command = connection.CreateCommand();
command.CommandText = "SELECT COUNT(*) FROM dbo.Orders";
var result = await command.ExecuteScalarAsync(ct);
return Convert.ToInt32(result);
}
}
Configuration
MssqlOptions, configured through the Action<MssqlOptions> delegate passed
to AddPinqponqMssql:
| Property | Type | Default | Notes |
|---|---|---|---|
ConnectionString |
string |
"" (required) |
Standard Microsoft.Data.SqlClient connection string. |
RetryCount |
int |
3 |
Maximum retry attempts on transient failures. Must not be negative. |
RetryBaseDelay |
TimeSpan |
200ms |
Base delay for exponential backoff between retries (with jitter). Must be positive. |
Options are validated at startup via ValidateOnStart().
Main types
| Type | Kind | Purpose |
|---|---|---|
AddPinqponqMssql(Action<MssqlOptions>) |
DI extension (IServiceCollection) |
Registers an ISqlConnectionFactory with retry resiliency. |
AddPinqponqMssql(...) |
DI extension (IHealthChecksBuilder) |
Adds a SELECT 1 health check (name defaults to "mssql") that opens its own connection directly, bypassing the retry pipeline. |
ISqlConnectionFactory |
Interface | OpenConnectionAsync(ct) → SqlConnection, retrying transient failures per MssqlOptions. |
MssqlOptions |
Options | Connection string and retry configuration. |
SqlConnectionFactory, MssqlHealthCheck |
Implementations | Registered by the extension methods; not usually referenced directly. |
Notes / behavior
- Transient error classification.
SqlConnectionFactorywraps connection opening in a PollyResiliencePipelinethat retries on a curated set of well-known transient SQL Server error numbers — timeouts, throttling, failover, and network-level errors such as-2,20,64,233,10053,10054,10060,10928,10929,40197,40501,40613,49918,49919,49920,4060, and4221— plus anyTimeoutException. Errors outside this set (e.g. login failures, invalid object names) are not retried and propagate immediately. - A fresh
SqlConnectionper attempt. Each retry attempt constructs a newSqlConnectionand callsOpenAsync; a connection that fails to open is disposed before the next attempt, so no half-open connections leak across retries. - Health check bypasses retry.
MssqlHealthCheckopens its ownSqlConnectiondirectly fromConnectionStringand runsSELECT 1— it does not go throughISqlConnectionFactory's retry pipeline, so a single failed attempt is enough to reportUnhealthy. - No connection pooling layer of its own. Connection pooling is handled
by
Microsoft.Data.SqlClientitself (ADO.NET connection pooling), not duplicated by this package. - No repositories, no entities. This package only opens connections. Data access patterns, table mapping, and migrations are entirely up to the consuming application.
Related packages
Samples
Try this package in the browser via Pinqponq.Playground — see samples/README.md.
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.3.0)
- Microsoft.IdentityModel.Tokens (>= 8.3.0)
- Polly.Core (>= 8.4.2)
-
net8.0
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 8.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.3.0)
- Microsoft.IdentityModel.Tokens (>= 8.3.0)
- Polly.Core (>= 8.4.2)
-
net9.0
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.18)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Options (>= 9.0.18)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.3.0)
- Microsoft.IdentityModel.Tokens (>= 8.3.0)
- Polly.Core (>= 8.4.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.