Search code examples
c#entity-frameworksql-server-ce-4

Entity Framework 6.1.3 and SQL Server CE 4.0 - Code First Setup a password to protect sdf file


I am using Entity Framework 6.1.3 along with SQL Server CE 4.0. Is there anyway to put a password on the generated sdf file the first time it is created?

 <connectionStrings>
    <add name="SQLCompactTest" connectionString="Data Source=|DataDirectory|SqlCeTest.sdf;Password=aaa;" providerName="System.Data.SqlServerCe.4.0" />
  </connectionStrings>

I try to add a Password field in my connection string but it does not add a password to the sdf file.

Thank you.


Solution

  • Adding a Password field in the connection string DOES add a password to the created sdf. You just have to make sure the connectionstring is used by entityframework, which tripped me over.