UrticaDioica UrticaDioica - 1 year ago 117
C# Question

System.Data.SQLite - cannot access an encrypted database

I set an encryption key for my database in DB Browser for SQLite and now I cannot access it in C#.

Here's the relevant code:

private SQLiteConnection connection;

public DbManager()
connection = new SQLiteConnection("Data Source=DB\\gamedb.encrypted.sqlite;Password=p4ssw0rd;Version=3;");

below throws an exception: "file is encrypted or is not a database".

public Dictionary<string, string> ReadMaps()
SQLiteDataReader reader = new SQLiteCommand("select * from Map", connection).ExecuteReader();
Dictionary<string, string> res = new Dictionary<string, string>();
while (reader.Read())
res[(string)reader["Name"]] = (string)reader["Data"];
return res;

Is the key specified in the DB browser a different thing than a password?

Answer Source

I decided to handle setting the password by coding, it works. I created a new project for setting/clearing the password.

Here's the code:

    SQLiteConnection conn;

    // (code omitted)

    private void setPwButton_Click(object sender, EventArgs e)
        if (!String.IsNullOrEmpty(passwordTextBox.Text))
            MessageBox.Show("Please specify a password!");

    private void clearPwButton_Click(object sender, EventArgs e)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download