//Allows user to configure database connection private void Configure_Database_Button_Click(object sender, EventArgs e) { this.Hide(); Change_Connection change = new Change_Connection(); change.ShowDialog(); change.Focus(); }
//Tests the connection public static void testConnection(Form currentForm) { //Connection is read from a textfile in the app domain directory try { Global.setConnectionString("ConnectionString.dat"); } //If file not found loads a new form where you can choose the database from a folder dialog //Text file is found in the app domain base directory catch (FileNotFoundException ex) { currentForm.Close(); Change_Connection change = new Change_Connection(); change.ShowDialog(); change.Focus(); } using (Global.connection = new SQLiteConnection(Global.connectionString)) { try { Global.connection.Open(); Global.connection.Close(); } //Any other outlying exception will be caught here. //A new form will load and allow the user to choose a new database from a file dialog catch (SQLiteException ex) { MessageBox.Show("Error loading database. Please choose another database\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); currentForm.Hide(); Change_Connection cc = new Change_Connection(); cc.ShowDialog(); cc.Focus(); } } }