Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. using MySql.Data.MySqlClient;
  2. using System.Windows.Forms;
  3.  
  4. namespace CourseProject
  5. {
  6. class Db
  7. {
  8. public static MySqlConnection connection = new MySqlConnection("SERVER=192.168.0.163;DATABASE=tsp2;UID=tsp;PASSWORD=123;");
  9.  
  10. public static bool OpenConnection()
  11. {
  12. try
  13. {
  14. connection.Open();
  15. return true;
  16. }
  17. catch (MySqlException ex)
  18. {
  19. switch (ex.Number)
  20. {
  21. case 0:
  22. MessageBox.Show("Cannot connect to server.");
  23. break;
  24.  
  25. case 1045:
  26. MessageBox.Show("Invalid username/password");
  27. break;
  28. }
  29. return false;
  30. }
  31. }
  32.  
  33. public static bool CloseConnection()
  34. {
  35. try
  36. {
  37. connection.Close();
  38. return true;
  39. }
  40. catch (MySqlException ex)
  41. {
  42. MessageBox.Show(ex.Message);
  43. return false;
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement