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
.
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.
// 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();
Any feedback or issues for this package can be added to the issues in GitHub.
This package is licensed under the Apache 2.0 license.