Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Base_de_Datos.Conexion conn = new Base_de_Datos.Conexion();
  2. Base_de_Datos.Conexion myconection = new Base_de_Datos.Conexion();
  3. connection = conn.iniciarBD();
  4. aprobar = myconection.OpenConnection();
  5.  
  6. public MySqlConnection iniciarBD()
  7. {
  8. server = "localhost";
  9. database = "presupuesto";
  10. uid = "root";
  11. password = "";
  12. string connectionString;
  13. connectionString = "SERVER=" + server + ";" + "DATABASE=" +
  14. database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
  15. connection = new MySqlConnection(connectionString);
  16. return connection;
  17.  
  18. }
  19.  
  20. public bool OpenConnection()
  21. {
  22. try
  23. {
  24. connection.Close();
  25. connection.Open(); ---- Aqui sale el error
  26. return true;
  27. }
  28. catch (MySqlException ex)
  29. {
  30. //When handling errors, you can your application's response based
  31. //on the error number.
  32. //The two most common error numbers when connecting are as follows:
  33. //0: Cannot connect to server.
  34. //1045: Invalid user name and/or password.
  35. switch (ex.Number)
  36. {
  37. case 0:
  38. MessageBox.Show("No se pudo conectar al servidor. Contacta con el administrador");
  39. break;
  40.  
  41. case 1045:
  42. MessageBox.Show("Contraseña o usario Invalidos, porfavor intentelo de nuevo");
  43. break;
  44. }
  45. return false;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement