/// <summary> /// Tests the DB-Connection /// </summary> /// <param name="pOnlineDBConDat">DB connection data</param> /// <param name="messageOnSuccess">Show a messagebox when the connection is successfull</param> /// <returns></returns> public static bool TestConnection(WrapMySQLData pOnlineDBConDat, bool messageOnSuccess = true) { bool success = false; using (WrapMySQL sql = new WrapMySQL(pOnlineDBConDat)) { try { sql.Open(); success = true; } catch { success = false; } finally { sql.Close(); } } if (success) { if (messageOnSuccess) { MessageBox.Show("Connection to the database established successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Could not connect to the database.", "Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(success); }
public void WrapMySQL_ConnectionTest_ExpectSuccess() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); sql.Close(); } }
public void WrapMySQL_SQLScalarUntypedString_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); object res = sql.ExecuteScalar("SELECT QDValue FROM qd_info WHERE QDKey = ?", "DefaultDomain"); sql.Close(); Assert.AreEqual("endevx", Convert.ToString(res)); } }
public void WrapMySQL_SQLScalarUntypedInt_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); object res = sql.ExecuteScalar("SELECT COUNT(*) FROM qd_drives"); sql.Close(); Assert.AreEqual(10, Convert.ToInt32(res)); } }
public void WrapMySQL_SQLScalarTypedInt_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); int res = sql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_drives"); sql.Close(); Assert.AreEqual(10, res); } }