How do I connect to LocalDB in VS2017 Pro

Jon Jacobs 86 Reputation points
2021-04-20T17:23:27.3+00:00

I installed SQL Server Express 2017 LocalDB, rebooted my computer, launched VS with one of my projects, selected TOOLS | Connect to Database
My choices are:
Microsoft SQL Server which always fails with:
a network-specific or instance-specific error occurred...
and
Microsoft SQL Server database file
but I do not know the name of the file

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Cris Zhan-MSFT 6,661 Reputation points
    2021-04-21T09:37:30.107+00:00

    Hi,

    You can get a list of all instances of LocalDb from the command prompt with the SqlLocalDb.exe program, which is in your PATH by default:

    sqllocaldb info  
    

    SqlLocalDB.exe is a simple tool that enables the user to easily manage LocalDB instances from the command line.

    You can try to use SSMS to connect to localdb instance in (LocalDB)\LocalDBApp1 format.

    The easiest way to use LocalDB is to connect to the automatic instance owned by the current user by using the connection string Server=(localdb)\MSSQLLocalDB;Integrated Security=true. To connect to a specific database by using the file name, connect using a connection string similar to Server=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\MyDB1.mdf
    https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15#connect-to-the-automatic-instance

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 121.8K Reputation points MVP Volunteer Moderator
    2021-04-20T21:47:38.907+00:00

    Try (localdb)\MSSQLSERVER.

    If that does not help, open a command-line window and run sqllocaldb list to see which localdb instances you have. You may have to start them.

    sqllocaldb -? gives you available commands.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.