Rask.SqlServer 0.24.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Rask.SqlServer --version 0.24.0
                    
NuGet\Install-Package Rask.SqlServer -Version 0.24.0
                    
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="Rask.SqlServer" Version="0.24.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rask.SqlServer" Version="0.24.0" />
                    
Directory.Packages.props
<PackageReference Include="Rask.SqlServer" />
                    
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 Rask.SqlServer --version 0.24.0
                    
#r "nuget: Rask.SqlServer, 0.24.0"
                    
#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 Rask.SqlServer@0.24.0
                    
#: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=Rask.SqlServer&version=0.24.0
                    
Install as a Cake Addin
#tool nuget:?package=Rask.SqlServer&version=0.24.0
                    
Install as a Cake Tool

Rask.SqlServer

SQL Server for .NET apps on Entity Framework Core. UseRaskSqlServer(...) is a drop-in replacement for UseSqlServer that applies SET XACT_ABORT ON and a LOCK_TIMEOUT on every connection the context opens, sets a client command timeout, turns on transient-failure retrying, and fits Rask's cache key inside SQL Server's index key limit.

SQLite remains Rask's default, and for most single-developer products it is the right answer for a long time. This package is for when SQL Server is already the house database.

Install

dotnet add package Rask.SqlServer

Use

builder.Services.AddDbContextFactory<AppDbContext>((sp, o) => o
    .UseRaskSqlServer(sp)
    .AddInterceptors(sp.GetServices<ISaveChangesInterceptor>()));

UseRaskSqlServer(sp) reads the connection string from Rask:ConnectionStrings:App — a missing one is an error naming that key, never a guessed server — and every default below from the Rask:SqlServer section:

// appsettings.json
{
  "Rask": {
    "ConnectionStrings": {
      "App": "Server=db;Database=app;User Id=app;TrustServerCertificate=true"
    },
    "SqlServer": {
      "CommandTimeout": "00:00:10",
      "LockTimeout": "00:00:03",
      "Retry": { "MaxCount": 3 }
    }
  }
}

In production set them as environment variables (Rask__ConnectionStrings__App, Rask__SqlServer__LockTimeout). A configure delegate runs after the section and wins:

o.UseRaskSqlServer(sp, s => s.Retry.Enabled = false);

What the defaults do

Setting Default Why
CommandTimeout 30s SQL Server has no server-side statement timeout, so this client-side ceiling is the only bound on a runaway query. Rounded up to whole seconds, because SqlClient reads 0 as "wait forever".
LockTimeout 10s The analogue of SQLite's busy_timeout. Without it a statement stuck behind a lock waits out the command timeout and surfaces as a slow query. Must stay below CommandTimeout; TimeSpan.Zero waits indefinitely (the server default).
AbortOnError true SET XACT_ABORT ON. With it off, a statement error inside an explicit transaction leaves that transaction open and holding locks — and in a web app the connection returns to the pool in that state.
Retry.Enabled / MaxCount / MaxDelay on / 6 / 30s SQL Server's own EnableRetryOnFailure, which already knows the transient error numbers, the Azure SQL failover set included.

SQL Server takes no session settings in the connection string, so XACT_ABORT and LOCK_TIMEOUT are one batch sent each time EF opens a connection — a round trip per open, since SqlClient resets a pooled connection's state. Code that opens the DbConnection directly skips it; open through context.Database.OpenConnectionAsync(). The same batch also sends SET TRANSACTION ISOLATION LEVEL READ COMMITTED: a transaction begun at another level (BeginTransaction(IsolationLevel.Serializable)) leaves that level on the session, the pool's reset does not clear it, and the next read on that connection would otherwise run serializable.

Retrying is an execution strategy, and like every EF Core retrying strategy it refuses a transaction you opened yourself outside it: wrap a hand-written BeginTransaction in context.Database.CreateExecutionStrategy().ExecuteAsync(...), or set s.Retry.Enabled = false.

The cache key

A SQL Server index key holds at most 900 bytes — 450 nvarchar characters. Rask.Cache configures its key at 512 so SQLite and PostgreSQL keep the room, which SQL Server only admits with a warning. UseRaskSqlServer caps that one key at 450 in the model; no other entity is touched, and SQLite apps get no migration. A longer key still cannot be stored on SQL Server — ICache rejects it with an error naming the limit, so hash long keys.

What stays behind

Litestream continuous backup and file snapshots (Rask.SQLite.Litestream, Rask.SQLite.Snapshots) are SQLite-only by definition — they replicate and copy a file. On SQL Server, backup is BACKUP DATABASE or your provider's snapshots. Migrations are unchanged: dotnet ef (and rask db) are provider-agnostic.

Full documentation: https://github.com/pal-tamas/rask/blob/main/docs/data.md#sql-server

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Rask.SqlServer:

Package Downloads
Rask.Server

The ASP.NET host for Rask, a full-stack .NET web framework, with every battery: database (SQLite or SQL Server, and PostgreSQL with the Rask.Postgres package, picked by Rask:Database:Provider), mediator and query cache, accounts, background jobs, transactional email, cache, file storage, outbox, operator dashboard, durable logs, Web Push, SQLite snapshots and continuous backup. Renders Rask components with live updates over a WebSocket. RaskApp.Create(args).Run<App>() is the whole Program.cs, and RaskApp.Create(args).Serve() the whole server of a WebAssembly client; app.Configure(c => c.Jobs.Off()) is how an app does without one. Depends on Rask, the shared core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.24.1-alpha.0.154 41 11/19/2026
0.24.1-alpha.0.149 41 11/18/2026
0.24.1-alpha.0.145 39 11/18/2026
0.24.1-alpha.0.141 40 11/18/2026
0.24.1-alpha.0.140 96 11/18/2026
0.24.1-alpha.0.137 41 11/18/2026
0.24.1-alpha.0.136 44 11/18/2026
0.24.1-alpha.0.102 43 11/18/2026
0.24.1-alpha.0.101 50 11/17/2026
0.24.1-alpha.0.100 39 11/17/2026
0.24.1-alpha.0.98 46 11/17/2026
0.24.1-alpha.0.93 39 11/17/2026
0.24.1-alpha.0.91 37 11/17/2026
0.24.1-alpha.0.90 44 11/17/2026
0.24.1-alpha.0.88 45 11/17/2026
0.24.1-alpha.0.52 43 11/17/2026
0.24.1-alpha.0.51 57 11/16/2026
0.24.1-alpha.0.43 51 11/16/2026
0.24.0 94 11/16/2026
Loading failed