SQL Server: How to find all localdb instance names
Asked Answered
I

5

51

I have two versions (2012, 2014) of SQL Server Express LocalDB installed in my system.

How can I find all existing LocalDB instance names?

I found a way to do that using command line as mentioned in the answers section.

Is there a better and easy way to do it?

Intercourse answered 22/3, 2016 at 14:30 Comment(0)
I
81

I found SqlLocalDB utility that needs to be run on command line.

SqlLocalDB can be found in

C:\Program Files\Microsoft SQL Server\110\Tools\Binn

or

C:\Program Files\Microsoft SQL Server\120\Tools\Binn

To get all existing LocalDB instance names, use:

SqlLocalDB.exe i

 info|i
  Lists all existing LocalDB instances owned by the current user
  and all shared LocalDB instances.

To get detailed information about a specific LocalDB instance:

SqlLocalDB.exe i "MSSQLLocalDB"

info|i "instance name"
  Prints the information about the specified LocalDB instance.
Intercourse answered 22/3, 2016 at 14:30 Comment(0)
R
30

To list all localdb instances, take a look vineel's answer!


If you want to list all databases of your default localdb instance using UI, look here (might not work with SSMS2019 anymore):

Just open your SSMS and connect to (LocalDB)\MSSQLLocalDB.
Now you will see all your LocalDB-Instances.

This works at least with SS2016.

enter image description here

Rump answered 25/2, 2018 at 12:20 Comment(3)
Thanks :-) works for me in SSMS 2017 and for SSMS2019 did not workHousework
This is incorrect, you're only connecting to the default MSSQLLocalDB instance (and listing the databases). This does not list all instance names!Nottingham
This is totally incorrect even with the SSMS (SS2016) it only shows one instance that is MSSQLLocalDB. There might be more than that instances such as V11.0, ProjectsV12, ProjectsV13. Why this answer got many upvotes?Vinaya
M
7

Here is the method i am using to get all instances from command line -

    internal static List<string> GetLocalDBInstances()
    {
        // Start the child process.
        Process p = new Process();
        // Redirect the output stream of the child process.
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.Arguments = "/C sqllocaldb info";
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        p.Start();
        // Do not wait for the child process to exit before
        // reading to the end of its redirected stream.
        // p.WaitForExit();
        // Read the output stream first and then wait.
        string sOutput = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        //If LocalDb is not installed then it will return that 'sqllocaldb' is not recognized as an internal or external command operable program or batch file.
        if (sOutput == null || sOutput.Trim().Length == 0 || sOutput.Contains("not recognized"))
            return null;
        string[] instances = sOutput.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
        List<string> lstInstances = new List<string>();
        foreach (var item in instances)
        {
            if (item.Trim().Length > 0)
                lstInstances.Add(item);
        }
        return lstInstances;
    }
Mycenaean answered 6/5, 2017 at 18:35 Comment(0)
C
7

In Visual Studio 2017 the SQL Server Object Explorer will show you all of the LocalDb instances

Chiachiack answered 13/2, 2018 at 13:25 Comment(1)
Thanks. This still works in VS 2022. So definitely an easy way without running any commands.Gnathous
M
5

In Visual Studio 2019 Server Explorer (or SQL Server Object Explorer button there) click "Add SQL Server" button

Add SQL Server Button

and expand the Local tab to view the list of local SQL Server currently running services it finds. Only when you connect to the selected server it will get listed in SQL Server Object Explorer:

SQL Server Object Explorer

Margo answered 3/2, 2021 at 14:34 Comment(1)
Good explanation and giving different (to find visually) and correct answer to the OPs question.Vinaya

© 2022 - 2024 — McMap. All rights reserved.