Skip to content
SQL LocalDB Wrapper is a .NET library providing interop with the Microsoft SQL Server LocalDB Instance API
C# PowerShell
Branch: master
Clone or download

Latest commit

martincostello Merge pull request #263 from martincostello/dependabot/nuget/Humanize…
…r-2.8.26

Bump Humanizer from 2.8.11 to 2.8.26
Latest commit fd5e268 Jun 3, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update GitHub Actions SDK version May 19, 2020
.vscode Fix incorrect path in VS Code launch configuration Aug 5, 2018
samples Merge pull request #263 from martincostello/dependabot/nuget/Humanize… Jun 3, 2020
src Revert Microsoft.Data.SqlClient update May 18, 2020
tests/SqlLocalDb.Tests Bump xunit.runner.visualstudio from 2.4.1 to 2.4.2 Jun 3, 2020
.editorconfig Add a .vsconfig file Apr 18, 2020
.gitattributes Publish NuGet packages separately Apr 13, 2020
.gitignore Publish NuGet packages separately Apr 13, 2020
.vsconfig Add a .vsconfig file Apr 18, 2020
CHANGELOG Update README and changelog Sep 20, 2019
CODE_OF_CONDUCT.md Fix incorrect link Aug 5, 2018
CommonAssemblyInfo.cs Initial rewrite for version 2 Aug 5, 2018
Directory.Build.props Bump ReportGenerator from 4.6.0 to 4.6.1 Jun 2, 2020
Directory.Build.targets Enable deterministic builds May 31, 2020
LICENSE Rename LICENSE file Apr 17, 2017
NuGet.config Remove extra NuGet feeds Sep 23, 2019
SqlLocalDb.ruleset Migrate main assembly to VS 2017 Apr 17, 2017
SqlLocalDb.sln Add a .vsconfig file Apr 18, 2020
SqlLocalDb.snk Migrate main assembly to VS 2017 Apr 17, 2017
build.ps1 Publish NuGet packages separately Apr 13, 2020
global.json Update to .NET Core 3.1.300 SDK May 19, 2020
readme.md Use GitHub Actions for CI Apr 12, 2020
stylecop.json Initial rewrite for version 2 Aug 5, 2018
update-dotnet-sdk.ps1 Fix SDK update May 19, 2020

readme.md

SQL LocalDB Wrapper

SQL LocalDB Wrapper is a .NET Standard 2.0 library providing interop with the Microsoft SQL Server LocalDB Instance API from managed code using .NET APIs.

NuGet

Build status

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 Core 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 Core SDK to be installed (version 3.1.201 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.

Copyright and Trademarks

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

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

You can’t perform that action at this time.