简体   繁体   English

在 C# 中设置和更改 SQLite 数据库密码

[英]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.我正在我的代码中实现 SQLite 功能,我可以在其中创建一个 SQLite 数据库文件并与之通信。 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.但是,System.Data.SQLite.SQLiteConnection 中不存在 ChangePassword() 或 SetPassword() 方法,因此它不起作用。 So my question is, am I missing something?所以我的问题是,我错过了什么吗?

I'm using the latest release of the official SQLite Nuget Package.我正在使用官方 SQLite Nuget 包的最新版本。

The method is not supported in the .net Core (.net Standard) version of the library.该方法在库的 .net Core (.net Standard) 版本中不受支持。

For connecting to a password-protected database, specify the password in the connection string.要连接到受密码保护的数据库,请在连接字符串中指定密码。 Use the SQLiteConnectionStringBuilder.Password or SQLiteConnectionStringBuilder.HexPassword properties.使用SQLiteConnectionStringBuilder.PasswordSQLiteConnectionStringBuilder.HexPassword属性。

For setting a password or changing the password, issue an sql pragma statement.要设置密码或更改密码,请发出 sql pragma语句。

pragma key='NewPassword'

or或者

pragma rekey='NewPassword'

For details see Using the "key" PRAGMA有关详细信息,请参阅使用“键”PRAGMA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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