2017-08-28 126 views
0

我使用FluentMigrator在C#中使用FluentMigrator.Runner.MigrationRunner創建SqlLite數據庫。我不知道有什麼方法可以在需要創建數據庫時使用SetPassword命令或SqlConnection命令嗎?有一個SqLiteRunnerContextFactory對象,但它似乎不是我可以用來指定密碼的屬性。FluentMigrator創建密碼保護SqlLite DB

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())); 
    } 

我想避免在連接時設置密碼之前查看文件是否存在。

回答

0

那麼,最後,下面的代碼通過每次創建de runner時使用SetPassword完美工作。不需要檢查文件是否存在。第一次它用密碼創建它,第二次它打開它似乎使用它來打開數據庫。這正是我正在尋找的。