MartinCostello.SqlLocalDb 3.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MartinCostello.SqlLocalDb --version 3.3.0                
NuGet\Install-Package MartinCostello.SqlLocalDb -Version 3.3.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="MartinCostello.SqlLocalDb" Version="3.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MartinCostello.SqlLocalDb --version 3.3.0                
#r "nuget: MartinCostello.SqlLocalDb, 3.3.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.
// Install MartinCostello.SqlLocalDb as a Cake Addin
#addin nuget:?package=MartinCostello.SqlLocalDb&version=3.3.0

// Install MartinCostello.SqlLocalDb as a Cake Tool
#tool nuget:?package=MartinCostello.SqlLocalDb&version=3.3.0                

SQL LocalDB Wrapper

SQL LocalDB Wrapper is a .NET library providing interop with the Microsoft SQL Server LocalDB Instance API from managed code using .NET APIs. The library targets netstandard2.0, net6.0 and net8.0.

NuGet

Build status codecov OpenSSF Scorecard

Introduction

This library exposes types that wrap the native SQL LocalDB Instance API to perform operations on SQL LocalDB such as for managing instances (create, delete, start, stop) and obtaining SQL connection strings for existing instances.

Microsoft SQL Server LocalDB 2012 and later is supported for both x86 and x64 on Microsoft Windows and the library targets netstandard2.0.

While the library can be compiled and referenced in .NET applications on non-Windows Operating Systems, SQL LocalDB is only supported on Windows. Non-Windows Operating Systems can query to determine that the SQL LocalDB Instance API is not installed, but other usage will cause a PlatformNotSupportedException to be thrown.

Installation

To install the library from NuGet using the .NET SDK run:

dotnet add package MartinCostello.SqlLocalDb

Basic Example

// using MartinCostello.SqlLocalDb;

using var localDB = new SqlLocalDbApi();

ISqlLocalDbInstanceInfo instance = localDB.GetOrCreateInstance("MyInstance");
ISqlLocalDbInstanceManager manager = instance.Manage();

if (!instance.IsRunning)
{
    manager.Start();
}

using SqlConnection connection = instance.CreateConnection();
connection.Open();

// Use the SQL connection...

manager.Stop();

Further Examples

Further examples of using the library can be found by following the links below:

  1. The wiki.
  2. The sample application.
  3. The examples written as tests.
  4. The library's own tests.

Migrating from System.Data.SqlLocalDb 1.x

Version 1.x.x of this library was previously published as System.Data.SqlLocalDb. The current version (3.x.x) has been renamed and is a breaking change to the previous version with various changes to namespaces and types.

Migrating from MartinCostello.SqlLocalDb 2.x

Version 2.x.x of this library uses SQL types from the System.Data.SqlClient namespace.

The current version (3.x.x) uses the new Microsoft.Data.SqlClient NuGet package where the same types (such as SqlConnection) are now in the Microsoft.Data.SqlClient namespace.

To migrate a project from using the previous 2.x release, you should change usage of the System.Data.SqlClient namespace to Microsoft.Data.SqlClient and recompile your project.

Feedback

Any feedback or issues can be added to the issues for this project in GitHub.

Repository

The repository is hosted in GitHub: https://github.com/martincostello/sqllocaldb.git

License

This project is licensed under the Apache 2.0 license.

Building and Testing

Compiling the library yourself requires Git and the .NET SDK to be installed (version 8.0.100 or later).

For all of the tests to be functional you must also have at least one version of SQL LocalDB installed.

To build and test the library locally from a terminal/command-line, run the following set of commands:

Windows

git clone https://github.com/martincostello/sqllocaldb.git
cd sqllocaldb
./build.ps1

Note: To run all the tests successfully, you must run either build.ps1 or Visual Studio with administrative privileges. This is because the SQL LocalDB APIs for sharing LocalDB instances can only be used with administrative privileges. Not running the tests with administrative privileges will cause all tests that exercise such functionality to be skipped.

Note: Several tests are skipped on non-Windows Operating Systems as SQL LocalDB itself is only supported on Windows.

This library is copyright (©) Martin Costello 2012-2022.

Microsoft SQL Server is a trademark and copyright of the Microsoft Corporation.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on MartinCostello.SqlLocalDb:

Package Downloads
Luxoft.Framework.AutomationCore

Package Description

IsolatedSqlDb

Package Description

CSharpSqlTests

A simple framework for running sql tests against a temprary localdb instance, optionally deploying a dacpac, using a nice fluent c# api

Alethic.SqlServer.Deployment

Package Description

FlakEssentials.SqlEx

Package Description

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on MartinCostello.SqlLocalDb:

Repository Stars
ardalis/Specification
Base class with tests for adding specifications to a DDD model
MoonStorm/FastCrud
fast .NET ORM for strongly typed people
SQLStreamStore/SQLStreamStore
Stream Store library targeting RDBMS based implementations for .NET
lithnet/access-manager
Access Manager provides web-based access to local admin (LAPS) passwords, BitLocker recovery keys, and just-in-time administrative access to Windows computers in a modern, secure, and user-friendly way.
Version Downloads Last updated
3.4.0 194,640 2/2/2024
3.3.0 74,817 11/14/2023
3.2.0 354,057 4/1/2022
3.1.0 132,943 11/8/2021
3.0.1 149,842 7/12/2021
3.0.0 340,942 10/10/2019
2.0.0 317,394 10/1/2018
2.0.0-beta1 1,383 8/12/2018