views:

23

answers:

1

OK, here is the szenario:

I'm coding a .NET 3.5 WPF-Aapplication, using the Microsoft Entity Framework to use a compact database file (.sdf) for storing data. On my first program start a computer-based encryption key is calculated and saved into the registry and my sdf-File should become encrypted with this key (or rather with a somehow hashed version of this key).

My current proble

  1. How can I encrypt my (until now unencrypted) sdf-file with the generated password?
  2. How can I tell the ModelContainer of the Entity Framework to use this password to connect to the database instead of the connection string in the app.config where no password is saved?

I tried to clear all connection strings and create a new one with the password on-the-fly when starting, but I get an exception that my configuration is read-only.

Any ideas are greatly appreciated :-)

+1  A: 

To change the database from being unprotected to protected, you must use the SqlCeEngine Compact method (in the System.Data.SqlServerCe ADO.NET provider)

To modify the connectionstring, see this: http://stackoverflow.com/questions/3556509/sql-ce-3-5-entityframework/3620434#3620434

SqlCeEngine engine = new SqlCeEngine("Data Source = AdventureWorks.sdf");
engine.Compact("Data Source=; Password =a@3!7f$dQ;");
ErikEJ