简体   繁体   中英

Setting and changing SQLite database password in C#

I'm implementing SQLite functionality in my code, where I can create an SQLite database file and communicate with it. I can't, however, password protect it. I've seen a lot of solutions, for example:

conn = new SQLiteConnection(connectionString);
conn.ChangePassword("Password");

However, the methods ChangePassword() or SetPassword() doesn't exist in System.Data.SQLite.SQLiteConnection, so it won't work. So my question is, am I missing something?

I'm using the latest release of the official SQLite Nuget Package.

The method is not supported in the .net Core (.net Standard) version of the library.

For connecting to a password-protected database, specify the password in the connection string. Use the SQLiteConnectionStringBuilder.Password or SQLiteConnectionStringBuilder.HexPassword properties.

For setting a password or changing the password, issue an sql pragma statement.

pragma key='NewPassword'

or

pragma rekey='NewPassword'

For details see Using the "key" PRAGMA

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