命令执行过程中遇到致命错误 c# mysql [英] fatal error encountered during command execution c# mysql

查看:56
本文介绍了命令执行过程中遇到致命错误 c# mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

给出如下连接字符串

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

使用 SQL 参数,您的应用程序对 sql 注入攻击广泛开放

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

这篇关于命令执行过程中遇到致命错误 c# mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆