0
Hello I’m a beginner in programming and I’m having trouble connecting Mysql in c#, where the code does not check and goes to catch action. Follows the code:
conexaoDataSet = new DataSet();
conexao = new MySqlConnection("SERVER=127.0.0.1; DATABASE=tcc; UID=root; PASSWORD=;");
try
{
conexao.Open();
MySqlCommand verifica = new MySqlCommand("SELECT * FROM CMS_pilots WHERE nome='" + txt_login.Text + "' and senha ='" + txt_senha.Text + "'", conexao);
bool resultado = verifica.ExecuteReader().HasRows;
if (resultado == true)
{
conexao.Close();
adm f2 = new adm();
f2.Show(this);
Hide();
}
else
{
MessageBox.Show("Login inválido!");
conexao.Close();
}
}
//erro acontece a partir de aqui
catch
{
MessageBox.Show("Erro de conexão com o banco de dados");
conexao.Close();
}
}
}
}
Hello Nayanne, welcome to Sopt. To increase your chances of getting an answer, you’d better include the code instead of the image.
– gustavox
Hello, I recommend you read that and that post in the help section on how to format a post here on Sopt.
– ptkato
In the block of
catch
, change the line tocatch (Exception ex)
. And in the message, switch toMessageBox.Show("Erro de conexão, detalhes: " + ex.Message);
. This will give you details of what is happening. Edit your question with the error that is returned to you.– Rafael Almeida