title: How to set the right AttachDbFilename relative path in ASP.NET Core?
body: <p>Working in VS2015 on a web project based on ASP.NET Core (former ASP.NET 5), .NET Core CLR RC1, EF Core (former EF 7), EF Migrations enabled, LocalDb v11.0.</p>
  
  <p>I manually (through SQL commands) created a database and placed MDF/LDF files in a project subdirectory, a situation similar to:</p>
  
  <pre class="lang-bash prettyprint-override"><code>MySolution\src\MyProject\MyLocalData\
    - MyLocalDb.mdf
    - MyLocalDb_log.ldf
  </code></pre>
  
  <p>This is the value of <code>"ConnectionString"</code> key set in <code>appsettings.json</code> (or at least, one of the many I tried):</p>
  
  <pre class="lang-js prettyprint-override"><code>"Data Source=(LocalDb)\\v11.0;AttachDbFilename=.\\MyLocalData\\MyLocalDb.mdf;Integrated Security=True"
  </code></pre>
  
  <p>The initial migration has been created correctly, now I'm stuck at <code>dnx ef database update</code> command (see <a href="http://ef.readthedocs.io/en/latest/platforms/aspnetcore/new-db.html" rel="noreferrer">official tutorial</a>), which gives this error:</p>
  
  <blockquote>
    <p>Error Number:15350,State:1,Class:14
    An attempt to attach an auto-named database for file .\MyLocalData\MyLocalDb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.</p>
  </blockquote>
  
  <p>I'm pretty sure there's no other DB with that name, having checked both in my user home directory for files, and in Sql Server Management Studio for databases in LocalDb instance. As a matter of fact, if I switch to an absolute filepath in <code>AttachDbFilename</code>, the migration moves further (and finds other errors related to column properties set through EF fluent interface, but that's another story).</p>
  
  <p>So it looks to me this is all a matter of finding the right <strong>relative</strong> path to use in <code>AttachDbFilename</code>. I searched here on SO for related topics, but could not find any answer. I also tried changing the relative path imagining that the <em>current</em> folder was <code>wwwroot</code>, or the <code>artifacts</code> folder, but with no luck.</p>
  
  <p>Does any one know how to correctly set this? TA</p>