• Stars
    star
    226
  • Rank 176,514 (Top 4 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SQL LocalDB Wrapper is a .NET library providing interop with the Microsoft SQL Server LocalDB Instance API

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 and net6.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 7.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.

Copyright and Trademarks

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

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

More Repositories

1

dotnet-minimal-api-integration-testing

An example of integration testing ASP.NET Core Minimal hosting and APIs
C#
321
star
2

xunit-logging

Logging extensions for xunit
C#
249
star
3

SignInWithAppleSample

A sample implementation of Sign in with Apple using ASP.NET Core
C#
45
star
4

lambda-test-server

A NuGet package that provides an in-memory test server for testing AWS Lambda functions
C#
31
star
5

dotnet-bumper

Upgrades projects to a newer version of .NET
C#
25
star
6

dotnet-playwright-tests

.NET tests using Playwright
C#
24
star
7

update-dotnet-sdk

A GitHub Action that updates the .NET SDK
TypeScript
18
star
8

dependabot-helper

An application that helps manage Dependabot updates across multiple repositories.
C#
14
star
9

alexa-london-travel-site

The companion site for the London Travel Amazon Alexa skill
C#
14
star
10

website

Martin Costello's website
C#
13
star
11

adventofcode

Solutions for Advent of Code in C#
C#
11
star
12

costellobot

GitHub automation for my repositories.
C#
10
star
13

apple-fitness-workout-mapper

Visualise multiple journeys from Apple Fitness on a map
C#
9
star
14

applepayjs-typings

TypeScript typings for Apple Pay JS
TypeScript
9
star
15

dotnet-macos-notarization-example

An example of implementing notarization for a self-contained .NET application on macOS
PowerShell
9
star
16

polly-rate-limiting

An example of using Polly's RateLimit policy in a ASP.NET Core Minimal API
C#
9
star
17

antiforgery-testing-application-part

Sample application for integration testing ASP.NET Core applications using antiforgery protections
C#
8
star
18

browserstack-automate

.NET client for the BrowserStack Automate REST API
C#
8
star
19

alexa-london-travel

An Amazon Alexa skill for checking the status of travel in London
C#
8
star
20

MinimalApisWithJsonSourceGenerator

Sample application that uses the .NET 6 JSON source generator with Minimal APIs
C#
8
star
21

api

Martin Costello's API
C#
7
star
22

dotnet-core-selenium-tests

A simple test implemented in .NET Core for Selenium
C#
7
star
23

update-static-assets

A GitHub Action that updates HTML static assets
TypeScript
6
star
24

openapi-extensions

Extensions for Microsoft.AspNetCore.OpenApi
C#
6
star
25

aspnetcore-openapi

A demonstration of different ways to add OpenAPI (Swagger) support to ASP.NET Core applications
C#
5
star
26

rebaser

A GitHub Action that can resolve basic version conflicts between Git branches
TypeScript
5
star
27

aspnet-core-pseudo-localization

An example application that demonstrates using pseudo-localization with ASP.NET Core
C#
5
star
28

dotnet-patch-automation-sample

Sample repository that demonstrates automated monthly patching of .NET applications
C#
5
star
29

dotnet-8-samples

Samples for new features in .NET 8
C#
4
star
30

project-euler

My solutions for problems on https://projecteuler.net/
C#
3
star
31

aspnet-core-7-samples

Samples for ASP.NET Core 7
C#
3
star
32

presentations

Content for public presentations πŸ›
3
star
33

crank-sandbox

A sandbox for playing with the crank .NET performance testing tool
PowerShell
3
star
34

benchmarks-dashboard

A dashboard for visualising benchmark results from benchmarkdotnet-results-publisher
C#
2
star
35

wait-for-nuget-package

Waits for a new version of a NuGet package to be published
C#
2
star
36

dotnet-lambda-annotations

Playground repo for Amazon.Lambda.Annotations
C#
2
star
37

benchmarks-demo

Demonstrates continuous benchmarking in GitHub Actions using BenchmarkDotNet
C#
2
star
38

twitterarchiveparser

Parses the JSON of Twitter archives
C#
2
star
39

Refit-Json-Benchmarks

Benchmarks for (de)serializing JSON using Refit
C#
2
star
40

credit-card-splitter

An application to split parts of a credit card bill between two people
JavaScript
2
star
41

blog

Martin Costello's blog
HTML
1
star
42

cdn

Source content for my CDN
1
star
43

nugetpackagestidier

Tidies up NuGet packages in your local NuGet package folders.
C#
1
star
44

polly-sandbox

A sandbox repository for integrating Polly
C#
1
star
45

martincostello

Martin Costello's README
1
star
46

azure-functions

Contains custom Azure Functions
C#
1
star
47

Update-DotNet-Core-SDK

A PowerShell script that can be used by GitHub Actions to keep your .NET SDK up-to-date
PowerShell
1
star
48

bootstrap

Scripts to setup a new computer
PowerShell
1
star
49

benchmarks

Repository for storing benchmark results
1
star
50

benchmarkdotnet-results-publisher

A GitHub Action that publishes results from BenchmarkDotNet benchmarks to a GitHub repository
TypeScript
1
star
51

github-automation

GitHub automation
TypeScript
1
star