I am using EF 6.0 and SQL Server CE 4.0. The .sdf 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:
The specified password does not match the database password
Code:
using (var context = new MyDbContext("ExamManagement"))
{
context.Database.Initialize(false);
}
Connection string:
<connectionStrings>
<add name="ExamManagement"
connectionString="Data Source=|DataDirectory|Pikeman.sdf;Max Database Size=4091;Password=123;"
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)1.<>c__DisplayClass7.b__5()
at System.Data.Entity.Core.Objects.ObjectQuery
at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()1.MoveNext()
at System.Data.Entity.Internal.LazyEnumerator
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)

Passwordpart is ignored..sdffrom the target directory, executing the code above will create a new.sdffile at the target directory without any exception. However, the newly created database is NOT password protected. Again, it seems that thePasswordpart is ignored.context.Database.Connection.Open();ornew SqlCeConnection("Data Source=|DataDirectory|Pikeman.sdf;Max Database Size=4091;Password=123;").Open();and let us know.