title: How to open a password protected SQL Server CE database with Entity Framework
body: <p>I am using EF 6.0 and SQL Server CE 4.0. The <code>.sdf</code> file is password protected, which I verified by opening the file with LinqPad. When I try to open this database in code with the following connection string, I get an exception:</p>
  
  <blockquote>
    <p>The specified password does not match the database password</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>using (var context = new MyDbContext("ExamManagement"))
  {
      context.Database.Initialize(false);
  }
  </code></pre>
  
  <p>Connection string:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="ExamManagement" 
           connectionString="Data Source=|DataDirectory|Pikeman.sdf;Max Database Size=4091;Password=123;" 
           providerName="System.Data.SqlServerCe.4.0" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TN4vB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/TN4vB.png" alt="enter image description here"></a>
  Stack trace:</p>
  
  <blockquote>
    <p>at System.Data.Entity.Core.EntityClient.EntityConnection.Open()<br>
    at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)<br>
    at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func<code>1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)<br>
    at System.Data.Entity.Core.Objects.ObjectQuery</code>1.&lt;>c__DisplayClass7.b__5()<br>
    at System.Data.Entity.Core.Objects.ObjectQuery<code>1.GetResults(Nullable</code>1 forMergeOption)<br>
    at System.Data.Entity.Core.Objects.ObjectQuery<code>1.&lt;System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator&gt;b__0()<br>
    at System.Data.Entity.Internal.LazyEnumerator</code>1.MoveNext()<br>
    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)  </p>
  </blockquote>