简体   繁体   中英

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;");
        connection.Open();
    }

The SQLiteCommand 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?

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))
            conn.ChangePassword(passwordTextBox.Text);
        else
            MessageBox.Show("Please specify a password!");
    }

    private void clearPwButton_Click(object sender, EventArgs e)
    {
        conn.ChangePassword(String.Empty);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM