Pinqponq.Database.Mssql 1.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Pinqponq.Database.Mssql --version 1.0.2
                    
NuGet\Install-Package Pinqponq.Database.Mssql -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pinqponq.Database.Mssql" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pinqponq.Database.Mssql" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Pinqponq.Database.Mssql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pinqponq.Database.Mssql --version 1.0.2
                    
#r "nuget: Pinqponq.Database.Mssql, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pinqponq.Database.Mssql@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pinqponq.Database.Mssql&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Pinqponq.Database.Mssql&version=1.0.2
                    
Install as a Cake Tool

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, or net10.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. SqlConnectionFactory wraps connection opening in a Polly ResiliencePipeline that 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, and 4221 — plus any TimeoutException. Errors outside this set (e.g. login failures, invalid object names) are not retried and propagate immediately.
  • A fresh SqlConnection per attempt. Each retry attempt constructs a new SqlConnection and calls OpenAsync; a connection that fails to open is disposed before the next attempt, so no half-open connections leak across retries.
  • Health check bypasses retry. MssqlHealthCheck opens its own SqlConnection directly from ConnectionString and runs SELECT 1 — it does not go through ISqlConnectionFactory's retry pipeline, so a single failed attempt is enough to report Unhealthy.
  • No connection pooling layer of its own. Connection pooling is handled by Microsoft.Data.SqlClient itself (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.

Samples

Try this package in the browser via Pinqponq.Playground — see samples/README.md.

Repository

https://github.com/pinqponq/pinqnuqets

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 121 10/17/2026
1.0.2 114 10/6/2026
1.0.1 152 8/7/2026
1.0.0 137 8/7/2026