I'm trying to learn how to create basic C# programs in Visual Studio 2015 with a MySQL database connection.
I'm working on a login form that checks the database for an unencrypted username and password match and displays a message box confirming correct or incorrect.
It works, but the response time is about 15 seconds! The table only has 4 rows it should be basically instantaneous as it's localhost.
Please help. The application I'm planning on writing needs a fast response time and will have a LOT more data to query.
EDIT: I've now written another program that just opens the connection and displays a message. No selecting. It still takes around 15 secs for a response. So the slow response is to with establishing the connection are there any common causes of this? I'm using Windows 10
private void button1_Click(object sender, EventArgs e)
{
try
{
string myConnection = "datasource=localhost;port=3306;username=root;password =root";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand selectCommand = new MySqlCommand("select * from database1.edata where user_name='"
+ this.username_txt.Text + "' and password='" + this.pwd_txt.Text + "' ;", myConn);
MySqlDataReader myReader;
myConn.Open();
myReader = selectCommand.ExecuteReader();
int count = 0;
while (myReader.Read())
{
count += 1;
}
if (count == 1)
{
MessageBox.Show("Username and Password accepted...Access Granted :)");
}
else if (count > 1)
{
MessageBox.Show("Duplicate username and password found....Access Denied :(");
}
else
{
MessageBox.Show("Incorrect Details entered...Access Denied :(");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}