Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class ConexaoBancoMySql
  2. {
  3. private static MySqlConnection objconexao = null;
  4.  
  5. // string mysql acessa o banco do servidor de hospedagem
  6. private String stringconnection1 = "datasource=localhost;port=3306;username=root;password=1010";
  7.  
  8. #region metodos que tentam abrir conexao com projeto rodando local ou hospedado
  9.  
  10. public void tentaAbrirConexaoLocal()
  11. {
  12. objconexao = new MySqlConnection();
  13. objconexao.ConnectionString = stringconnection1;
  14. objconexao.Open();
  15. }
  16. #endregion
  17.  
  18. public ConexaoBancoMySql()
  19. {
  20. try
  21. {
  22. tentaAbrirConexaoLocal();
  23. }
  24. catch (Exception)
  25. {
  26. Console.WriteLine("Não foi possível validar seu acesso.");
  27.  
  28. }
  29. }
  30.  
  31. public static MySqlConnection getConexao()
  32. {
  33. new ConexaoBancoMySql();
  34. return objconexao;
  35. }
  36.  
  37. public static void fecharConexao()
  38. {
  39. objconexao.Close();
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement