How to protect a *.sdf (sqlCE file) with a password
Is there a way to protect a *.sdf (sqlCE file) with a password or implement a similar security measure?
i try this:
if (!File.Exists(SDK))
{
SqlCeEngine engine = new SqlCeEngine("Data Source=" + SDK + "; Case Sensitive=True");
engine.CreateDatabase();
OpenConn();
SqlCeCommand CMD = new SqlCeCommand();
CMD = Conn.CreateComma开发者_如何学Gond();
CMD.CommandText = "Create table MEN(Code int ,Fname nvarchar(50),Lname nvarchar(50))";
CMD.ExecuteNonQuery();
}
where to change to have password ?
Since SQL CE 2000 password protection is possible:
CREATE DATABASE "secure.sdf"
DATABASEPASSWORD '<enterStrongPasswordHere>'
more here and here
The Visual Studio 2010 extension SQL Server Compact Toolbox can be used to create a database with a password. Encryption of the database is handled automatically once the password is set. The only catch is you need to create a new database with a password using the extension; it cannot password protect existing .sdf files. If you need to keep your existing structure: backup your data and/or schema, and reapply to the new one.
A layered approach, like most security solutions, is typically best and can be applied here. It is important to check (and correct) the encryption state of the file on the operating system level as well. You could even go above and beyond by encrypting the actual .sdf file inside of your run-time.
A good article on that here.
Cheers
Depending on what kind of protection you are looking for, you can password protect your database as well encrypt it.
If you're going to take advantage of either of those options, I believe you have to create the database in SQL Server Management Studio rather than letting Visual Studio create one for you. Take a look at the following page for instructions (page is for Sql CE 4 but should apply to other versions as well):
Dean Hume - A Simple Guide to SQL Compact 4
精彩评论