I was using Access database on my application and I switched to SQL Server, but it is not working properly... This is a Login screen, the Connect button click event.
When I connect it just skips and closes the login window with whatever info I put in it.
This is the error I'm getting. It's red at the cmd field, and I don't know why.
https://i.stack.imgur.com/gJ5hm.png
Code:
private void btnconectar_Click(object sender, EventArgs e)
{
if (!(empty(boxlogin.Text) && empty(boxsenha.Text)))
{
SqlCommand cmd = new SqlCommand("SELECT * from Usuarios where StrCmp(login, '" + boxlogin.Text + "')=0 and StrCmp(senha, '" + boxsenha.Text + "')=0",connection);
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 15;
connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
nome = reader["nome"].ToString();
login = reader["login"].ToString();
senha = reader["senha"].ToString();
msg("Login realizado com sucesso!\nBem vindo(a), " + nome.Substring(0, nome.IndexOf(" ")),Color.Green, false);
connection.Close();
timer4.Start();
}
else
{
msg("Usuário e/ou senha incorretos!", Color.Red, false);
}
}
else msg("Os campos não podem ficar em branco!", Color.Red, false);
connection.Close();
}
Output after execution:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll 'WindowsFormsApplication1.vshost.exe' (CLR v4.0.30319: WindowsFormsApplication1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_pt-BR_b77a5c561934e089\mscorlib.resources.dll'. Module was built without symbols.