Regira.DAL.SqlServer 6.5.0

dotnet add package Regira.DAL.SqlServer --version 6.5.0
                    
NuGet\Install-Package Regira.DAL.SqlServer -Version 6.5.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="Regira.DAL.SqlServer" Version="6.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Regira.DAL.SqlServer" Version="6.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Regira.DAL.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 Regira.DAL.SqlServer --version 6.5.0
                    
#r "nuget: Regira.DAL.SqlServer, 6.5.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 Regira.DAL.SqlServer@6.5.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=Regira.DAL.SqlServer&version=6.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Regira.DAL.SqlServer&version=6.5.0
                    
Install as a Cake Tool

Regira DAL — SQL Server

Regira DAL.SqlServer provides SQL Server backup/restore through the server's own BACKUP DATABASE / RESTORE DATABASE (settings, options, and backup/restore services — no CRUD or communicator surface). No client tools are needed: both statements run over an ordinary connection.

Projects

Project Package Backend CRUD Backup / Restore
DAL.SqlServer Regira.DAL.SqlServer SQL Server — ✓ (native .bak)

Installation

<PackageReference Include="Regira.DAL.SqlServer" Version="6.*" />

SqlServerSettings

Property Type Description
Host string Server name, host\instance or (localdb)\MSSQLLocalDB; default "localhost"
DatabaseName string? Target database
Username string? SQL login; null connects with Windows authentication
Password string? SQL login password
Port string Default "1433"; any other port is appended as host,port
UseSecure bool Require an encrypted connection; default false
TrustServerCertificate bool Accept the server's certificate without validating it
UseStrictEncryption bool Encrypt=Strict — TLS before the login (TDS 8.0, SQL Server 2022) — instead of Mandatory
var settings = new SqlServerSettings("localhost", "shop", "sa", "pass");
string cs    = settings.BuildConnectionString();

For any other authentication mode (Microsoft Entra ID, a managed identity), set SqlServerOptions.ConnectionString instead of DbSettings. Microsoft.Data.SqlClient 7 ships those Authentication=Active Directory … modes in a separate package, so the application also references Microsoft.Data.SqlClient.Extensions.Azure.

SqlServerBackupService / SqlServerRestoreService

Both work on the database named in the connection (Database / Initial Catalog).

var options = new SqlServerOptions
{
    DbSettings      = new SqlServerSettings("localhost", "shop", "sa", "pass"),
    BackupDirectory = @"D:\SqlBackups",
    Overwrite       = true
};

// second parameter is an optional ILogger
IMemoryFile backup = await new SqlServerBackupService(options).Backup();
await new SqlServerRestoreService(options).Restore(backup);

The backup directory

SQL Server writes and reads the .bak file itself: on its own file system, under its own service account. BackupDirectory is therefore required, and it must be reachable from both sides — SQL Server's service account and this process each need read and write access.

BackupDirectory is the path as SQL Server sees it. LocalBackupDirectory is the same directory as this process sees it, and defaults to BackupDirectory, which is right when both run on one machine.

SQL Server runs BackupDirectory LocalBackupDirectory
On this machine D:\SqlBackups —
On another machine, folder shared D:\SqlBackups \\db01\SqlBackups
In a Linux container (-v C:\sqlbackups:/var/opt/mssql/backup) /var/opt/mssql/backup C:\sqlbackups

The instance's own backup folder (MSSQL\Backup) usually admits only the service account and administrators, so an application can rarely read it. Every call uses a new file and deletes it afterwards; a file this process cannot delete is left in place with a logged warning. When a backup cannot be read because LocalBackupDirectory does not lead to it, SQL Server is asked to delete the file itself (xp_delete_files, or xp_delete_file before SQL Server 2019), which needs sysadmin; without it, the warning names the file left on the server.

Backup

Backup() takes a copy-only full backup, so the differential base and log chain of a scheduled backup plan are left untouched. The returned file holds the whole .bak in memory.

Restore

Restore(file) connects through master and creates the target database from the backup:

  • An existing target database throws, unless Overwrite = true: then it is taken offline, rolling back its open sessions, and dropped. That happens only after SQL Server has read the backup's file list, so a file it cannot open never costs you the existing database. Offline, no application can reconnect before the drop; SQL Server keeps an offline database's files, and the restore overwrites them where they sit at the paths below — a file elsewhere is named in a logged warning.
  • The data and log files go to the server's default data and log directories, named after the target database (shop_staging.mdf, shop_staging_log.ldf), so a backup restores under a new name beside its source.
  • A planned file that belongs to another database — one renamed, or taken offline — fails the restore before anything is dropped. A target that did not exist is restored without REPLACE, so a stray file at a planned path fails the restore rather than being overwritten.

Exists checks for a database on an open connection:

bool exists = await restoreService.Exists(connection, "shop_staging");

Neither service joins an ambient TransactionScope: SQL Server refuses to back up or restore inside a transaction. Backup needs db_backupoperator (or db_owner) on the database; restore needs dbcreator.

Backup/Restore contracts

Both services implement the shared contracts from Common:

public interface IDbBackupService  { Task<IMemoryFile> Backup(); }
public interface IDbRestoreService { Task Restore(IMemoryFile file); }

Overview

  1. Index — Settings, the backup directory, backup and restore
  2. Examples — Copy a database under a new name, archive a backup and restore it later

License

Apache License 2.0 — this package contains no license validation and no runtime limits. See LICENSE. A few companion packages are commercially licensed with a free tier; see the licensing overview.

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 was computed.  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
6.5.0 42 10/4/2026
6.4.0 119 9/26/2026
6.3.3 89 9/22/2026
6.3.2 96 9/19/2026
6.3.1 96 9/17/2026