Skip to content Skip to sidebar Skip to footer

'local Database Runtime: Cannot Create Named Instance

I have a C# app that I am trying to make use of using LocalDB. As of now, when I start up my app, I am greeted by this error. Cannot create named instance. The parameter for the L

Solution 1:

  1. Purge by fire your computer of all non-SQL 2014 LocalDb or higher instances. As of this writing, I'm using the SQL-2014 version.

  2. Make your EF connection xml in the App.Config look something like this.

    <system.data.localdb><localdbinstances><addname="MyNamedInstance"version="12.0" /></localdbinstances></system.data.localdb><connectionStrings><addname="DiaProdConnection"connectionString="Data Source=(localdb)\MyNamedInstance;Initial 
           Catalog=MovieDB;Integrated 
           Security=True;AttachDbFilename=|DataDirectory|MovieDB.mdf"providerName="System.Data.SqlClient" /></connectionStrings>
  3. Many examples will have that field |DataDirectory| in their connection string. Unfortunately, what they won't tell you is that that string isn't a special string known by the framework, but is instead a variable that you have to assign and set yourself. For that, I call this code at the entry point of my application.

    AppDomain.CurrentDomain.SetData("DataDirectory",
        Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)); 
    

Keep in mind, that if the DB exists on the system but in a different location, the connector will throw an error.

Running

Sqllocaldb.exei

Should help you see if an instance exists and from there you can decide if it needs to be deleted.

I'm horrified by how poor the documentation is on the errors and how obnoxious the whole thing seemed.

Post a Comment for "'local Database Runtime: Cannot Create Named Instance"