Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add LocalDB to Visual Studio 2015 Community's SQL Server Object Explorer?

Problem

I don't understand how to make LocalDB show up in the SQL Server Object Explorer. On some VMs, it shows up automatically, on some other VMs, it doesn't. Still, after googling for hours, I don't get it.

Current situation

  1. I have a clean VM
  2. I installed Visual Studio 2015 Community (all default settings)
  3. I let a console application run (Entity Framework 6, code-first, console application) which worked on another VM and created a database automatically which then showed up in the SQL Server Object Explorer; but not this time

The error says:

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) ---> System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified 

So, on this VM, no database gets created and nothing shows up in the SQL Server Object Explorer's SQL Server node.

Connecting to LocalDB

What I think to know

  • Visual Studio 2015 Community comes with LocalDB; so everything should just work out of the box, but it doesn't, and I don't know why
  • LocalDB databases are just a pair of files (*.mdf and *.ldf)
  • I've seen the files being created at the default database location at C:\Users\<username>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB; but on this VM, there is no such folder
  • The App.config looked every time like this (and it was automatically created that way when I installed Entity Framework 6 the NuGet Package Manager in Visual Studio):

App.config

<configuration>   <configSections>     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections>   <entityFramework>     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">       <parameters>         <parameter value="mssqllocaldb" />       </parameters>     </defaultConnectionFactory>     <providers>       <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />     </providers>   </entityFramework> </configuration> 

Other random comments

  • Earlier, with SQL Server, it was necessary to open up certain ports, but LocalDB runs, as I understand it, as a separate process on demand when started by Visual Studio.
  • I don't know how to debug the SQLException
  • Does LocalDB not come packaged with Visual Studio 2015 Community and do I need to install it separately?
like image 518
Lernkurve Avatar asked Sep 28 '15 19:09

Lernkurve


People also ask

How do I enable LocalDB?

Install LocalDB through the installation wizard or by using the SqlLocalDB. msi program. LocalDB is an option when installing SQL Server Express LocalDB. Select LocalDB on the Feature Selection/Shared Features page during installation.


1 Answers

I had the same issue today recently installing VS2015 Community Edition Update 1.

I fixed the problem by just adding the "SQL Server Data Tools" from the VS2015 setup installer... When I ran the installer the first time I selected the "Custom" installation type instead of the "Default". I wanted to see what install options were available but not select anything different than what was already ticked. My assumption was that whatever was already ticked was essentially the default install. But its not.

like image 180
Gonzalo Lucero Avatar answered Oct 06 '22 01:10

Gonzalo Lucero