title: Use MDF with entityframework Core
body: <p>I'm trying to figure out how to connect to an .mdf file using entityframework core.  I found a resource on how to connect to one <a href="https://nodogmablog.bryanhogan.net/2018/02/using-an-mdf-file-database-with-entity-framework-core-2-in-visual-studio-2017/" rel="nofollow noreferrer">here</a> However it doesn't seem to be working.  I've made a var simple context using the Northwind dataset</p>
  
  <pre><code>public class Order
  {
      public int OrderId { get; set; }
      public string CustomerID { get; set; }
      public int EmployeeID { get; set; }
      public DateTime OrderDate { get; set; }
      // etc.
  }
  
  public class NorthwindContext : DbContext
  {
      public NorthwindContext(DbContextOptions options) : base(options) { }
      public DbSet&lt;Order&gt; Orders { get; set; }
  }
  </code></pre>
  
  <p>I've created a test class to attempt to connect to the DB</p>
  
  <pre><code>public string NorthwindConnectionString = @"Data Source=.\SQLEXPRESS;
                        AttachDbFilename=C:\source\Astoot\RestEzCore.Tests\TestDB\NORTHWND.MDF;
                        Integrated Security=True;
                        Connect Timeout=30;
                        User Instance=True";
  
  [TestMethod]
  public void TestMethod1()
  {
      var optionsBuilder = new DbContextOptionsBuilder&lt;NorthwindContext&gt;();
      //I've also tried UseSqlLite()
      optionsBuilder.UseSqlServer(this.NorthwindConnectionString);
      using (var context = new NorthwindContext(optionsBuilder.Options))
      {
          var orders = context.Orders.ToList();
          Assert.IsTrue(orders.Any());
      }
  }
  </code></pre>
  
  <p>However when I attempt to run my tests I get an error</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p><strong>Edit</strong></p>
  
  <p>I've also tried moving my MDF to users folder and connect using this connection string:</p>
  
  <blockquote>
    <p>Data Source=(LocalDB)\MSSQLLocalDB;DataBase=Northwind;Integrated Security=True;Connect Timeout=30"</p>
  </blockquote>
  
  <p>However this doesn't seem to work as well, it throws an exception</p>
  
  <blockquote>
    <p>SqlException: Cannot open database "Northwind" requested by the login. The login failed.
    Login failed for user 'MyUser'</p>
  </blockquote>
  
  <p>Is there something wrong with my connection string?</p>
  
  <p>I can't quite seem to figure out how to use an MDF with entityframework</p>