title: Entity Framework Connection String "The Server was not found"
body: <p>I have set up a Code First using the following DbContext</p>
  <pre><code>public class MyDatabaseDbContext : DbContext
  {
      public MyDatabaseDbContext(string nameOrConnectionString)
          : base(nameOrConnectionString)
      {
      }
  
      public MyDatabaseDbContext()
          : base(&quot;MyDatabase&quot;)
      {
      }
  
      public DbSet&lt;MyTable&gt; MyTables { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
      }
  }
  </code></pre>
  <p>I have also set up the connection string to look at the (Local) database</p>
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name=&quot;MyDatabase&quot; 
       connectionString=&quot;Server=(local);Database=MyDatabase;Trusted_Connection=True;MultipleActiveResultSets=true&quot;
       providerName=&quot;System.Data.SqlClient&quot;
       /&gt;
   &lt;/connectionStrings&gt;
  </code></pre>
  <p>Also set up the initializer in Global.asax</p>
  <pre><code>Database.SetInitializer&lt;MyDatabaseDbContext&gt;(new DropCreateDatabaseAlways&lt;MyDatabaseDbContext&gt;());
  </code></pre>
  <p>I then run the application and call the DbContext (in my case from the controller)</p>
  <pre><code>      var dbContext = new MyDatabaseDbContext();
        var myTableResults = dbContext.MyTables.ToList();
  </code></pre>
  <p>I get the follow error message</p>
  <blockquote>
  <p>An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code</p>
  <p>Additional information: 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: 50 - Local Database Runtime error occurred. Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.</p>
  </blockquote>
  <p>On Debugging and looking at the dbContext variable &gt; Database &gt; Connection &gt; ConnectionString Property I see the following:
  &quot;Data Source=(localdb)\v12.0;AttachDbFilename=|DataDirectory|MyDatabase.mdf;Initial Catalog=MyDatabase;Integrated Security=True;MultipleActiveResultSets=True&quot;</p>
  <p><strong>Questions</strong></p>
  <p>Why is it pointing to the (localDb)\v12.0 database and not my connection string?
  Even so, Why is it not creating the database there anyway as this is on my dev machine?</p>
  <p>Is there some kind of convention which I have forgotten about which I need to set.</p>