Reputation: 16092
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?
Upvotes: 274
Views: 337536
Reputation: 16092
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.Upvotes: 269
Reputation: 11
https://aspblogs.blob.core.windows.net/media/dixin/Open-Live-Writer/89ee21b2c263_49AE/image_thumb_5.png Windows Application Log Error Computer\HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\UserInstances{2DD3D445-34C1-4251-B67D-7DFEED432A87}
Just change ParentInstance to MSSQL14E.LOCALDB or MSSQL15E.LOCALDB.
Upvotes: 1
Reputation: 12898
Unlike the other answers, this approach uses:
- No special commands.
- No complicated configurations.
Just use the SQL Server Object Explorer
It's pretty straightforward...
{YourTableName}
table > View DesignerDone.
Upvotes: 54
Reputation: 33
With SQL Server 2017 and Visual Studio 2015, I used localhost\SQLEXPRESS
Upvotes: -1
Reputation: 12693
In Visual Studio 2012 all I had to do was enter:
(localdb)\v11.0
Visual Studio 2015 and Visual Studio 2017 changed to:
(localdb)\MSSQLLocalDB
as the server name when adding a Microsoft SQL Server Data
source in:
View/Server Explorer/(Right click) Data Connections/Add Connection
and then the database names were populated. I didn't need to do all the other steps in the accepted answer, although it would be nice if the server name was available automatically in the server name combo box.
You can also browse the LocalDB database names available on your machine using:
View/SQL Server Object Explorer.
Upvotes: 325
Reputation: 366
The fastest way in Visual Studio 2017 is to go to Tools -> SQL Server -> New query.. Choose from Local databases and choose the desired Database name at the bottom.
Alternative way
Visual Studio 2017 Server name is:
(localdb)\MSSQLLocalDB
Add the new connection using menu Tools -> Connect to Database...
Upvotes: 4
Reputation: 6872
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 with SqlLocalDB.exe info NAME
. Here's what it looks like on my machine:
> SqlLocalDB.exe info
MSSQLLocalDB
> SqlLocalDB.exe info MSSQLLocalDB
Name: mssqllocaldb
Version: 13.0.1601.5
Shared name:
Owner: DESKTOP-I4H3E09\simon
Auto-create: Yes
State: Running
Last start time: 4/12/2017 8:24:36 AM
Instance pipe name: np:\\.\pipe\LOCALDB#EFC58609\tsql\query
>
If it isn't running then you need to start it with SqlLocalDB.exe start MSSQLLocalDB
. When it is running you see the Instance pipe name:
which starts with np:\\
. Copy that named pipe string. Within VS2017 open the view Server Explorer
and create a new connection of type Microsoft SQL Server (SqlClient)
(don't be fooled by the other file types you want the full fat connection type) and set the Server 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 using dotnet 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://learn.microsoft.com/en-us/sql/tools/sqllocaldb-utility
Upvotes: 13
Reputation: 41
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
Upvotes: 4
Reputation: 26
I followed the steps above, but I forgot to install the SQL Server 2014 LocalDB before the Visual Studio 2015 configuration.
My steps are as follow:
Hope this help anybody.
Upvotes: 1
Reputation: 861
Select in :
Microsoft SQL Server (SqlClient)
(localdb)\MSSQLLocalDB
Use Windows Authentication
Press Refresh button to get the database name :)
Upvotes: 86
Reputation: 4530
Visual Studio 2015 RC, has LocalDb 12 installed, similar instructions to before but still shouldn't be required to know 'magic', before hand to use this, the default instance should have been turned on ... Rant complete, no for solution:
cmd> sqllocaldb start
Which will display
LocalDB instance "MSSQLLocalDB" started.
Your instance name might differ. Either way pop over to VS and open Server Explorer, right click Data Connections, choose Add, choose SQL Server, in the server name type:
(localdb)\MSSQLLocalDB
Without entering in a DB name, click 'Test Connection'.
Upvotes: 7
Reputation: 11
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.
Upvotes: 0
Reputation: 201
It worked for me.
Upvotes: 20
Reputation: 681
Fix doesn't work.
Exactly as in the example illustration, all these steps only provide access to "system" databases, and no option to select existing user databases that you want to access.
The solution to access a local (not Express Edition) Microsoft SQL server instance resides on the SQL Server side:
Done! Now you can select your local SQL Server from the Server Name list in Connection Properties.
Upvotes: 7