开发者

How to enable MS-SQL Compact Database encryption on first program run when using it with the Entity Framework?

开发者 https://www.devze.com 2023-01-18 06:16 出处:网络
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-ba

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 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;");
0

精彩评论

暂无评论...
验证码 换一张
取 消