0

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 Answer 1

1

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;");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.