SQL LocalDB Wrapper is a .NET assembly providing interop with the Microsoft SQL Server LocalDB native API.
C# Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

readme.md

SQL LocalDB Wrapper

Build Status Coverage Status

NuGet

Join the chat at https://gitter.im/martincostello/sqllocaldb

Build History

Overview

SQL LocalDB Wrapper is a .NET 4.0 assembly providing interop with the Microsoft SQL Server LocalDB native API from managed code using .NET APIs.

It is designed to support use of dependency injection by consumers by implementing interfaces, and is also designed to fit with the other data access providers defined under the System.Data namespaces.

The assembly supports using SQL Server LocalDB 2012 and 2014 for both the x86 and x64 platforms and SQL Server LocalDB 2016 for the x64 platform.

Downloads

The recommended way of obtaining the assembly is using NuGet.

Alternatively, a ZIP file containing the assembly can be downloaded from GitHub.

Documentation

Basic Usage

First install the NuGet package:

Install-Package System.Data.SqlLocalDb

Add the appropriate namespace:

using System.Data.SqlLocalDb;

Then create an instance, start it and connect to it:

ISqlLocalDbProvider provider = new SqlLocalDbProvider();
ISqlLocalDbInstance instance = provider.GetOrCreateInstance("MyInstance");

instance.Start();

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

    // Use the connection...
}

instance.Stop();

Further Details

For further documentation about the assembly and how to use it, consult the Wiki in GitHub.

You can also check out the examples below.

Examples

  1. An example of using the API can be found here in the TestApp project in the source code.
  2. An runnable example solution using the API to test an ASP.NET MVC application using SQL Server with MSTest is included as BlogSample.sln in the source code.

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

Building and testing the project is supported using Microsoft Visual Studio 2017.

The simplest way to build and test the assembly from the source code is by using the Build.ps1 script in the root of the repository like so:

.\Build.ps1

The project can also be built and tested from Visual Studio.

Building the project from the command-line using Build.ps1 invokes MSBuild to compile the source, examples and tests (including running the configured static analysis tools), and then uses MSTest to test the compiled assembly (System.Data.SqlLocalDb.dll).

The standard build process also includes running StyleCop.

To only compile the source code and not run the tests, use the following command:

.\Build.ps1 -RunTests $False

Note: To run all the tests, 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 marked as Inconclusive by MSTest.