0
private void button1_Click_1(object sender, EventArgs e)
  {
      try
      {
          string myConnection = " datasource=**.**.**.**;port=3306;username=****;password=****;";
          MySqlConnection myconn = new MySqlConnection(myConnection);
          MySqlCommand SelectCommand = new MySqlCommand(" select * from forma.user where username='" + this.username_txt.Text + "' and password= '" + this.password_txt.Text + "' ; ", myconn);

      MySqlDataReader myreader;
      myconn.Open();
      myreader = SelectCommand.ExecuteReader();
      int count = 0;
      while (myreader.Read())
      {
          count = count + 1;

      }
      if (count == 1)
      {
         // MessageBox.Show("Prijava uspešna");
          this.Hide();
          Form2 f2 = new Form2();
          f2.ShowDialog();
      }
      else if (count > 1)
      {

          MessageBox.Show("Podobojeno uporabniško ime");
      }
      else
      {
          MessageBox.Show("uporabniško ime ali geslo ni pravilno.");
          myconn.Close();
      }

  }

  catch (Exception ex)
  {
      MessageBox.Show(ex.Message);
  }
}

I have a problem connecting to remote server, it gives me error (title). Can you please tell me what I did wrong and how can I fix it? Thanks.

1

1 Answer 1

2

give the connection string as below

string myConnection = "Server=**.**.**.**;Port=3306;Database=***;Uid=***;Pwd=***;"

Use SQL parameters, your application is widely open for sql injection attacks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.