private async Task TestConnection() { try { using (UserDialogs.Instance.Loading("Testing database connection...")) { _connectedToDb = await Task.Run(() => _databaseConnectionChecker.TestConnection()); if (_connectedToDb) { _model.LoadParameters(); if (bool.Parse(ParametersLoader.Parameters[AppParameters.Remember]) && _appStart) { _appStart = false; _model.Username = ParametersLoader.Parameters[AppParameters.Username]; PasswordEntry.Text = ParametersLoader.Parameters[AppParameters.Password]; Login(ParametersLoader.Parameters[AppParameters.Password]); } } } } catch (ConnectionStringException) { _connectedToDb = false; } }
/// <summary> /// Run a database connection test. /// </summary> /// <param name="databaseConnectionTestDetails">Details about the database connection /// test that needs to be executed. The result of the connection test is applied to properties /// of this object.</param> protected override void Run(DatabaseConnectionTestDetails databaseConnectionTestDetails) { IDatabaseConnectionChecker databaseConnectionChecker = this.databaseConnectionCheckerFactory.CreateDatabaseConnectionChecker( databaseConnectionTestDetails.ProviderName); Exception testException = null; databaseConnectionTestDetails.WasTestSuccessful = databaseConnectionChecker.TestConnection( databaseConnectionTestDetails.ConnectionString, out testException); databaseConnectionTestDetails.WasTestRun = true; databaseConnectionTestDetails.ConnectionError = testException; if (testException != null) { databaseConnectionTestDetails.ConnectionErrorText = testException.ToString(); } }