'(Authentication to host "XXX.XXX.XXX.XXX" failed) when use the Mysql.Data.dll to connect mysql

When use the MySql.Data.dll to connect the mysql , sometimes the error occured (Authentication to host "XXX.XXX.XXX.XXX" failed) ,the code for this fuction is to get the tables of the selected databases.
but when i ping the IP for mysql it's ok, the version (8.0.29) for "Mysql.Data.dll" will cause this problem ?

''' // the code for get the tables public static List GetTables(string ip,string port, string user, string password, string databaseName)

        {   
            
        string connectionSql = $"server={ip};port={port};user={user};password={password};database={databaseName}";

        List<string> tables = new List<string>();
        MySqlConnection conn = new MySqlConnection(connectionSql);
        try
        {

            conn.Open();
            MySqlCommand cmd = new MySqlCommand("show tables", conn);
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                tables.Add(reader.GetString(0));
                // do nothing 
                //  Console.WriteLine("link successfully");
            }
            reader.Close();
            conn.Close();
        }
        catch (Exception ex)
        {
            conn.Close();
        }
        return tables;
    }       

'''



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source