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
- How can I encrypt my (until now unencrypted) sdf-file with the generated password?
- How can I tell the ModelContainer of the Entity Framework to use this password to connect to the database instead of the connec开发者_高级运维tion 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 :-)
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: SQL CE 3.5 & EntityFramework
SqlCeEngine engine = new SqlCeEngine("Data Source = AdventureWorks.sdf");
engine.Compact("Data Source=; Password =a@3!7f$dQ;");
精彩评论