private void btn_CheckConnection_Click(object sender, EventArgs e) { try { MysqlModel dbSettings = new MysqlModel(); dbSettings.Host = txt_ip.Text; dbSettings.Port = Convert.ToUInt16(txt_port.Text); dbSettings.User = txt_user.Text; dbSettings.Password = txt_pass.Text; dbSettings.Database = txt_authdb.Text; using (Mysql databaseConnection = new Mysql(dbSettings)) { if (databaseConnection.OpenConnection()) { if (databaseConnection.IsValidDatabase()) MessageBox.Show("Database connection successful.", RBACManagerModel.GetApplicationTitle()); else MessageBox.Show("Database connection successful but the selected database does not contain alle needed tables with the needed columns. \n\nUpdate the database or change the settings to connect to a valid database.", RBACManagerModel.GetApplicationTitle()); databaseConnection.CloseConnection(); } else MessageBox.Show("Can not connect to database.", RBACManagerModel.GetApplicationTitle()); } } catch(Exception) { MessageBox.Show("An error occured. Check your settings.", RBACManagerModel.GetApplicationTitle()); } }
public RBACManagerModel(string settingsPath) { this.settingsPath = settingsPath; databaseSettings = new MysqlModel(); ini = new IniFile(); LoadSettings(); mysqlConnection = new Mysql(databaseSettings); }
public Mysql(MysqlModel databaseSettings) { SetConnectionString(databaseSettings.Host, databaseSettings.Port, databaseSettings.User, databaseSettings.Password, databaseSettings.Database); connection = new MySqlConnection(connectionString); isOpen = false; }
public void UpdateConnection(MysqlModel databaseSettings) { bool opened = isOpen; CloseConnection(); SetConnectionString(databaseSettings.Host, databaseSettings.Port, databaseSettings.User, databaseSettings.Password, databaseSettings.Database); connection.ConnectionString = connectionString; if (opened) { OpenConnection(); } }