FluentMigrator创建受密码保护的SqlLite DB

时间:2017-08-28 17:22:28

标签: sqlite fluent-migrator

我使用FluentMigrator使用FluentMigrator.Runner.MigrationRunner在C#中创建SqlLite数据库。我想知道只有在需要创建数据库时,有没有办法在SqlConnection中使用SetPassword命令?有一个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()));
    }

我想避免在连接时设置密码之前查看文件是否存在。

1 个答案:

答案 0 :(得分:0)

嗯,最后,每次创建de runner时,使用SetPassword完美地完成下面的代码。无需检查文件是否存在。第一次用密码创建它,第二次用它打开它似乎用它来打开DB。这正是我想要的。