private static void OnValidateChanges(object sender, SettingsChangedEventArgs e) { Trace.TraceInformation("Main.OnValidateChanges fired"); if (!e.Changed.Contains(nameof(Settings.StorageProvider)) && !e.Changed.Contains(nameof(Settings.Database))) { return; } Trace.TraceInformation($"Main.OnValidateChanges relevant! type={e.NewSettings.StorageProvider}, db={e.NewSettings.Database}"); try { IDataStorage newStorage; switch (e.NewSettings.StorageProvider) { case DataStorageProvider.SQLite: newStorage = new SQLiteDataStorage(e.NewSettings.Database); break; case DataStorageProvider.MSSQL: newStorage = new MssqlDataStorage(e.NewSettings.Database); break; default: throw new Exception("Unknown enum value " + Settings.StorageProvider); } newStorage.TestConnection(); } catch (Exception ex) { var msg = $"Error validating the {e.NewSettings.StorageProvider} database '{e.NewSettings.Database}': {ex.Message}"; Trace.TraceError(msg + Environment.NewLine + ex.StackTrace); MessageBox.Show(msg, Resources.Title_CSV_Query_Error); e.Cancel = true; } }
public void TestConnectionWorks() { var db = new MssqlDataStorage("CsvQueryTest"); db.TestConnection(); }