在net core3中尝试访问加过密的sqlite数据库时会遇到错误:System.InvalidOperationException:“You specified a password in the connection string, but the native SQLite library 'e_sqlite3' doesn't support encryption.”
难道net core 3中不支持访问加密后的sqlite数据库了吗?答案是否定的,它有自己的规范,实现也是肯定的,我们只需要下面三行命令就可以解决问题。
dotnet remove package Microsoft.Data.Sqlite
dotnet add package Microsoft.Data.Sqlite.Core
dotnet add package SQLitePCLRaw.bundle_e_sqlcipher
意思就是重新引入SQLitePCLRaw.bundle_e_sqlciphe包,可在NuGet图形界面操作。另外说一下sqlLite连接字符串,当你不知道有哪些关键字时,可以像下面这样写。
SqliteConnectionStringBuilder sqliteConnection = new SqliteConnectionStringBuilder();
sqliteConnection.Password = "123456";
sqliteConnection.DataSource = dbPath;
sqliteConnection.Mode = SqliteOpenMode.ReadWriteCreate;
using (SqliteConnection conn = new SqliteConnection(sqliteConnection.ConnectionString))
{
conn.Open();
var command = conn.CreateCommand();
command.CommandText = “delete from table1 where id =1”;
command.ExecuteNonQuery();
}