Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ConexaoBancoMySql
- {
- private static MySqlConnection objconexao = null;
- // string mysql acessa o banco do servidor de hospedagem
- private String stringconnection1 = "datasource=localhost;port=3306;username=root;password=1010";
- #region metodos que tentam abrir conexao com projeto rodando local ou hospedado
- public void tentaAbrirConexaoLocal()
- {
- objconexao = new MySqlConnection();
- objconexao.ConnectionString = stringconnection1;
- objconexao.Open();
- }
- #endregion
- public ConexaoBancoMySql()
- {
- try
- {
- tentaAbrirConexaoLocal();
- }
- catch (Exception)
- {
- Console.WriteLine("Não foi possível validar seu acesso.");
- }
- }
- public static MySqlConnection getConexao()
- {
- new ConexaoBancoMySql();
- return objconexao;
- }
- public static void fecharConexao()
- {
- objconexao.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement