title: NHibernate Cannot attach the MDF
body: <p>I am trying to attach to a SQL Server Express LocalDB with NHibernate but I keep on getting the exception:</p>
  
  <blockquote>
    <p>An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.</p>
  </blockquote>
  
  <p>With the inner exception being:</p>
  
  <blockquote>
    <p>Cannot attach the file 'Test.mdf' as database 'Test'.</p>
  </blockquote>
  
  <p>I have encountered this error before when using Entity Framework and could fix it through:</p>
  
  <pre><code>&gt; sqllocaldb stop v11.0
  &gt; sqllocaldb delete v11.0
  </code></pre>
  
  <p>However that is not working in this instance. Below is my complete program:</p>
  
  <pre><code>using FluentNHibernate.Cfg;
  using FluentNHibernate.Cfg.Db;
  using FluentNHibernate.Mapping;
  using NHibernate.Tool.hbm2ddl;
  
  namespace Sandbox
  {
      public class Person
      {
          public virtual int Id { get; set; }
          public virtual string Name { get; set; }
      }
  
      public class PersonMap : ClassMap&lt;Person&gt;
      {
          public PersonMap()
          {
              Id(p =&gt; p.Id);
              Map(p =&gt; p.Name);
          }
      }
  
      public class Program
      {
          public static void Main(string[] args)
          {
              var connectionString =
                  @"Data Source=(LocalDB)\v11.0;AttachDBFilename=Test.mdf;" +
                  @"Initial Catalog=Test;Integrated Security=True";
  
              var _sessionFactory = Fluently.Configure()
                  .Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString))
                  .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;Program&gt;())
                  .ExposeConfiguration(cfg =&gt; new SchemaExport(cfg).Create(false, true))
                  .BuildSessionFactory();
          }
      }
  }
  </code></pre>