I can't believe I couldn't find a working solution to this after an hour of searching. I'm following this article on Entity Framework 6.0 which gives a simple walk-through on Code First. I created the project and installed the latest EF Nuget package for the project to compile. I also verified that I have Microsoft SQL Server 2012 Express LocalDB installed which came with Visual Studio 2013. I don't have any other instances of SQL installed on my local computer. The program runs and entries are added to the database and outputted in the console. But when the article says "check your localdb" it doesn't say how! I don't see any '.mdf' or '.ldf' files created under the project folder. I tried every way to connect Visual Studio's Server Explorer to LocalDB. The wizard cannot locate (localdb)
or cannot find any provider in Server Explorer to accept connection string like (localdb)\v11.0;Integrated Security=true;
I've seen this asked several places in StackOverflow but no answer works or marked as answer. Please help, this doesn't have to be this frustrating!
What are the steps to connect Visual Studio Server Explorer to LocalDB?
The following works with Visual Studio 2017 Community Edition on Windows 10 using SQLServer Express 2016.
Open a PowerShell check what it is called using
SqlLocalDB.exe info
and whether it is Running withSqlLocalDB.exe info NAME
. Here's what it looks like on my machine:If it isn't running then you need to start it with
SqlLocalDB.exe start MSSQLLocalDB
. When it is running you see theInstance pipe name:
which starts withnp:\\
. Copy that named pipe string. Within VS2017 open the viewServer Explorer
and create a new connection of typeMicrosoft SQL Server (SqlClient)
(don't be fooled by the other file types you want the full fat connection type) and set theServer name:
to be the instance pipe name you copied from PowerShell.I also set the
Connect to database
to be the same database that was in the connection string that was working in my Dotnet Core / Entity Framework Core project which was set up usingdotnet ef database update
.You can login and create a database using the
sqlcmd
and the named pipe string:sqlcmd -S np:\\.\pipe\LOCALDB#EFC58609\tsql\query 1> create database EFGetStarted.ConsoleApp.NewDb; 2> GO
There are instructions on how to create a user for your application at https://docs.microsoft.com/en-us/sql/tools/sqllocaldb-utility
Select in :
Microsoft SQL Server (SqlClient)
(localdb)\MSSQLLocalDB
Use Windows Authentication
Press Refresh button to get the database name :)
Scenario: Windows 8.1, VS2013 Ultimate, SQL Express Installed and running, SQL Server Browser Disabled. This worked for me:
You can now create a new connection with Server name: (LocalDb)\v11.0 (hit refresh) Connect to a database: Select your new database under the dropdown.
I hope it helps.
Use SQL Server Object Explorer (SSOX) Instead
It's pretty straightforward...
{YourTableName}
table > View DesignerDone.
Run the CMD as admin.
to find more about the instance type : SqlLocalDB info instanceName
now from VS you can setup your connection In VS, View/Server Explorer/(Right click) Data Connections/Add Connection Data Source: Microsoft SQL Server (SqlClient) Server name: (localdb)\MSSQLLocalDB Log on to the server: Use Windows Authentication Press "Test Connection", Then OK.
job done
OK, answering to my own question.
Steps to connect LocalDB to Visual Studio Server Explorer
SqlLocalDB.exe start v11.0
SqlLocalDB.exe info v11.0
(localdb)\v11.0
. If it didn't work, use the Instance pipe name that you copied earlier. You can also use this to connect with SQL Management Studio.