3

Closed

Default instance detection logic for LocalDB doesn't work with SQL Server 2014

description

Normally at package install time we try to detect a good default instance for creating SQL Server databases automatically. If an instance called SQLEXPRESS isn't available we usually try to detect LocalDB instances.

Apparently this logic depends on a naming convention that used to work in the LocalDB databases installed by VS 2012 and VS 2013, i.e. there is always a database called (localdb)\v11.0 if LocalDB v11 is installed. Once we find that v11.0 of LocalDB is installed we create the appropriate entry for a default connection factory:
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
But as soon as you install the SQL Server 2014 version of LocalDB in a machine, the logic will start creating invalid entries in the config, because the instances automatically created don't follow the same naming convention, e.g. the entry will look like this:
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v12.0" />
      </parameters>
    </defaultConnectionFactory>
But the only LocalDB instance created in the machine by default is called "ProjectsV12".

Note that the actual instances are located in the file system under %LOCALAPPDATA%\Microsoft\Microsoft SQL Server Local DB\Instances. Not sure if there is a corresponding registry entry.
Closed May 6, 2014 at 6:47 PM by lukew
Verified Fixed and unit tests have been updated

comments

ErikEJ wrote Apr 29, 2014 at 6:02 AM

@Diego Why is this an issue, Localdb 11 is always installed with VS 2012 & 2013?

Does the user only have VS 2010 installed? In that case, you cpuld default to always use Express, perhaps.

divega wrote Apr 29, 2014 at 7:35 AM

Hi Erik,

LocalDB 11 is what comes in the box, but now it is possible (and VS2013 is encouraging users) to upgrade to LocalDB 12 (i.e. the SQL Server 2014 version). As soon as someone does this we start adding the v12.0 in the config, but there is no such instance so when you hit F5 you'll get an error. VS2010 isn't involved.

divega wrote Apr 29, 2014 at 7:36 AM

We default to express when it is present, but nowadays if you just install VS you don't get express, so always using express is not an option.

ErikEJ wrote Apr 29, 2014 at 9:28 AM

I think there is an api to create instances, http://technet.microsoft.com/en-us/library/hh214784.aspx

divega wrote May 2, 2014 at 5:14 PM

We got information from the LocalDB team that from v12 on the name of the automatic instance has changed to be fixed to "(localdb)\mssqllocaldb" and that the documentation still needs to be updated. We are planning to implement this change in EF6.1.1.

ajcvickers wrote May 2, 2014 at 8:25 PM

Fixed in https://entityframework.codeplex.com/SourceControl/changeset/826d7f1900c50e73b03fd60fb31ab4526970ba6c

No deed poll filed for your name change... (Return "(localdb)\mssqllocaldb" for LocalDb versions of 12 or newer)

We got information from the LocalDB team that from v12 on the name of the automatic instance has changed to be fixed to "(localdb)\mssqllocaldb" and that the documentation still needs to be updated.

juvalencia wrote Nov 15, 2014 at 4:01 PM

Hi how do i fix my visual studio then, I am trying to run a project and I am still getting this problem. I have installed Update 4.

Do we have a step by step how to fix it??