private void cmdTest_Click_1(object sender, System.EventArgs e) { //Test database connection TstServerMySQL = txtServerHost.Text; TstPortMySQL = txtPort.Text; TstUserNameMySQL = txtUserName.Text; TstPwdMySQL = txtPassword.Text; TstDBNameMySQL = txtDatabase.Text; if (TstServerMySQL == "" || TstPortMySQL == "" || TstUserNameMySQL == "" || TstDBNameMySQL == "") { MessageBox.Show("Please Fill the input Box properly"); } else { try { SQLConn.conn.ConnectionString = "Server = '" + TstServerMySQL + "'; " + "Port = '" + TstPortMySQL + "'; " + "Database = '" + TstDBNameMySQL + "'; " + "user id = '" + TstUserNameMySQL + "'; " + "password = '******'"; SQLConn.conn.Open(); Interaction.MsgBox("Test connection successful", MsgBoxStyle.Information, "Database Settings"); } catch { Interaction.MsgBox("The system failed to establish a connection", MsgBoxStyle.Information, "Database Settings"); } SQLConn.DisconnMy(); } }
private void cmdSave_Click_1(object sender, System.EventArgs e) { TstServerMySQL = txtServerHost.Text; TstPortMySQL = txtPort.Text; TstUserNameMySQL = txtUserName.Text; TstPwdMySQL = txtPassword.Text; TstDBNameMySQL = txtDatabase.Text; String departmentId = txtDepartmentId.Text; if (TstServerMySQL == "" || TstPortMySQL == "" || TstUserNameMySQL == "" || TstDBNameMySQL == "") { MessageBox.Show("Please Fill the input Box properly"); } else { try { SQLConn.conn.ConnectionString = "Server = '" + TstServerMySQL + "'; " + "Port = '" + TstPortMySQL + "'; " + "Database = '" + TstDBNameMySQL + "'; " + "user id = '" + TstUserNameMySQL + "'; " + "password = '******'"; SQLConn.conn.Open(); SQLConn.DBNameMySQL = txtDatabase.Text; SQLConn.ServerMySQL = txtServerHost.Text; SQLConn.UserNameMySQL = txtUserName.Text; SQLConn.PortMySQL = txtPort.Text; SQLConn.PwdMySQL = txtPassword.Text; SQLConn.SaveData(); MessageDialog.ShowAlert("Settings saved successfully"); } catch { Interaction.MsgBox("The system failed to establish a connection", MsgBoxStyle.Information, "Database Settings"); } SQLConn.DisconnMy(); //save database } }