我有一个使用 Entity Framework Core 的 ASP.NET Core 控制台应用程序(针对 2.2 版)。我正在尝试连接到使用DB Browser for SQLCipher 创建的空的加密 SQLite 数据库。创建连接后,我正在尝试迁移数据库,但我得到了一个'SQLite Error 26: 'file is not a database'.'
这是我的代码:
var connection = new SqliteConnection(@"Data Source=Sqlite\test.db;");
connection.Open();
var command = connection.CreateCommand();
var password = "test";
command.CommandText = "SELECT quote($password);";
command.Parameters.AddWithValue("$password", password);
var quotedPassword = (string)command.ExecuteScalar();
command.CommandText = "PRAGMA key = " + quotedPassword;
command.Parameters.Clear();
var result = command.ExecuteNonQuery();
services.AddDbContext<SmartContext>(options =>
options.UseSqlite(connection));
var serviceProvider = services.BuildServiceProvider();
var context = serviceProvider.GetService<MyContext>();
Console.WriteLine("Migrating sqlite database");
context.Database.Migrate();
我能够连接到DB Browser和SQLiteStudio中的数据库。
我查看了这个存储库,我有SQLitePCLRaw.bundle_sqlcipher (1.1.11)、SQLitePCLRaw.bundle_green (1.1.11)、Microsoft.EntityFrameworkCore.Design (2.2.6)、Microsoft.EntityFrameworkCore.Sqlite.Core (2.2. 6)在我的项目中添加的包。
我看过很多论坛上的很多帖子,但没有一个提到使用加密数据库进行迁移。我可能遗漏了一些非常明显的东西,但是任何帮助解决这个错误将不胜感激,谢谢!