title: Error opening SQL Server Compact Edition 4.0 using Nhibernate
body: <p>I have the following setup in app.config:</p>
  
  <pre><code>&lt;hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" &gt;
      &lt;session-factory name="Nh.Data"&gt;
         &lt;property name="connection.provider"&gt;
             NHibernate.Connection.DriverConnectionProvider
         &lt;/property&gt;
         &lt;property name="dialect"&gt;
             NHibernate.Dialect.MsSqlCeDialect  &lt;/property&gt;
         &lt;property name="connection.driver_class"&gt;
             NHibernate.Driver.SqlClientDriver
         &lt;/property&gt;
         &lt;property name="connection.connection_string"&gt;
             Data Source=NhData.sdf
         &lt;/property&gt;
         &lt;property name="adonet.batch_size"&gt;16&lt;/property&gt;
         &lt;property name="generate_statistics"&gt;true&lt;/property&gt;
         &lt;property name="show_sql"&gt;true&lt;/property&gt;
         &lt;mapping assembly="Nh.Model"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>When using  the following code to access the database,</p>
  
  <pre><code>    private ISessionFactory CreateSessionFactory(){
          var cfg = new NHibernate.Cfg.Configuration().Configure();
          return cfg.BuildSessionFactory();
      }
  </code></pre>
  
  <p>I am getting the following error on the line <code>return cfg.BuildSessionFactory();</code></p>
  
  <pre><code>    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: Named Pipes Provider, error: 40 - Could not open a
      connection to SQL Server)
  </code></pre>
  
  <p>This is the same error I get when I change the connection property as recommended by <a href="http://connectionstrings.com/sql-server-2005-ce" rel="nofollow">Connection Strings.com</a> </p>
  
  <p>When I change the <code>connection.connection_string</code> property to <code>Data Source=|DataDirectory|\bin\Debug\NhData.sdf</code>, the error changes to</p>
  
  <pre><code>    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: 26 - Error Locating
      Server/Instance Specified)
  </code></pre>
  
  <p>I have the following files in the application folder to enable running of SQL Server Compact</p>
  
  <pre><code>    sqlceca40.dll      sqlcecompact40.dll           sqlceoledb40.dll
      sqlceer40EN.dll    sqlceme40.dll                sqlceqp40.dll
      sqlcese40.dll      System.Data.SqlServerCe.dll  NhData.sdf
  </code></pre>
  
  <p>I know the path to the database file is correct, as I can connect and test the connection from within the the visual studio IDE connection dialog. I have read and re-read <a href="http://msdn.microsoft.com/en-us/library/gg213826.aspx" rel="nofollow">private deployment vs. central deployment (SQL Server Compact)</a>. Any searches on the above errors return results which are not related to my problem.</p>
  
  <p>The laptop I am using is running Windows 7 Professional 64 Bit and I am using  post-build event to copy the database and the DLLs to the application folder.</p>
  
  <p>Is there something I'm missing or doing wrong?</p>