private void ConnectToDatabase() { cs.LoadConnectionConfig(); if (con != null && con.State == System.Data.ConnectionState.Open) { foreach (Form form in this.MdiChildren) { form.Close(); form.Dispose(); } con.Close(); } if (!cs.IsEmpty()) { con = new NpgsqlConnection(cs.GetConnectionString()); try { con.Open(); ownersService = new OwnersService(con); SetCurrentOwner(ownersService.GetDefaultOwner()); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } SetMenuChoices(); }