Search code examples
c#.netlocaldb

How to create LocalDB instance programmatically?


What is the .NET code equivalent of running below command?

sqllocaldb c <myInstance>

Please note that my question is NOT about creating a localdb database programmatically; rather creating an instance programmatically. I am trying to find about creating a new instance so that I can use (localdb)\myInstance in my connection string.

Update This is part of installing a desktop product. Creation of instance needs to happen on client machines that install this desktop product. As such, creating it using Visual Studio or SSMS is not the solution I'm looking for.

The closest answer I've gotten is @vasily.sib's Process.Start(). If no other option, this is what I will have to go with.


Solution

  • I used sqllocaldb package from https://github.com/martincostello/sqllocaldb. It works beautifully for programmatically doing all local db operations.