我在c#中有这个代码atm,并且MYSQL连接不起作用:
int chk;
MySqlConnection con = new MySqlConnection(@"Data Source=sql9.freemysqlhosting.net;port=3306;Initial Catalog=new;UserId=sql9FFFFF9;password=X3FFFFYX8;");
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from sql9164489.users where username='" + txt_user.Text + "' and password='" + txt_pass.Text + "'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
chk = Convert.ToInt32(dt.Rows.Count.ToString());
//If Correct
if (chk == 1)
{
MessageBox.Show("Connected");
}
else
{
MessageBox.Show("Incorrect");
}
con.Close();
答案 0 :(得分:1)
con.Opern()引发错误:
验证主机' sql9.freemysqlhosting.net'对于用户' sql9FFFFF9'使用方法' mysql_native_password'消息失败:用户访问被拒绝' sql9FFFFF9' 188.244.39.23' (使用密码:是)
我猜它很清楚
答案 1 :(得分:0)
下载.net的MySQL连接器,您的工作将更加轻松,因为数据库将显示在服务器资源管理器中,然后您可以从那里复制并粘贴连接字符串。 Here is link