我使用 FluentMigrator使用 FluentMigrator 在 C# 中使用 FluentMigrator.Runner.MigrationRunner 创建 SqlLite DB。我想知道有没有办法仅在需要创建数据库时使用 SetPassword 命令 o SqlConnection?有一个 SqLiteRunnerContextFactory 对象,但它似乎不是我可以用来指定密码的属性。
public MigrationRunner CreateMigrationRunner(string connectionString, string[] migrationTargets, Assembly assembly, long version)
{
var announcer = new TextWriterAnnouncer(Console.WriteLine) { ShowSql = true };
var options = new ProcessorOptions { PreviewOnly = false, Timeout = 60 };
var runnerContext = new SqLiteRunnerContextFactory().CreateRunnerContext(connectionString, migrationTargets, version, announcer);
var sqlLiteConnection = new SQLiteConnection(connectionString);
//If the DB has already been created, it crashes later on if I specify this
sqlLiteConnection.SetPassword("ban4an4");
return new MigrationRunner(assembly,
runnerContext,
new SQLiteProcessor(sqlLiteConnection,
new SQLiteGenerator(),
announcer,
options,
new SQLiteDbFactory()));
}
我想避免在连接时设置密码之前查看文件是否存在。
好吧,最后,下面的代码在每次创建 de runner 时使用 SetPassword 完美运行。无需检查文件是否存在。第一次它使用密码创建它,第二次打开它似乎使用它来打开数据库。这正是我想要的。