'System.AggregateException: 'One or more errors occurred.' -- SocketException: No such host is known

i'm trying to use mysqldatabase to save my data my it didn't work Here my setting on phpmyadmin Here my setting on phpmyadmin

Is there problem relate with verser of MySQL or phpmyadmin

Here error

And here my code in buttonLoginClick

private void ButtonLogin_Click(object sender, EventArgs e)
        {
            CONNECT conn = new CONNECT();
            DataTable table = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            MySqlCommand command = new MySqlCommand();
            String query = "SELECT * FROM `users` WHERE `username`=@usn AND `password`=@pass";

            command.CommandText = query;
            command.Connection = conn.getConnection();

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = guna2TextBoxUsername.Text;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = guna2TextBoxPassword.Text;

            adapter.SelectCommand = command;
            adapter.Fill(table);
            
            

            if (table.Rows.Count <= 0)
            {
                if (guna2TextBoxUsername.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your Username to Login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    guna2TextBoxUsername.Focus();
                }
                else if (guna2TextBoxPassword.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your Password to Login", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    guna2TextBoxPassword.Focus();
                }
                else
                {
                    MessageBox.Show("This Username Or Password Doesn't Exists", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    guna2TextBoxUsername.Clear();
                    guna2TextBoxPassword.Clear();
                    guna2TextBoxUsername.Focus();
                }
            }
            else
            {

                this.Hide();
                MainMenu mform = new MainMenu();
                mform.Show();
            }

And here is class CONNECT I used to connect data

 class CONNECT
    {
        private MySqlConnection connection = new MySqlConnection("datasource=hostlocal;port=3306;username=root;password=;database=csharp_hotel_db");
        public MySqlConnection getConnection()
        {
            return connection;
        }
        public void openConnection()
        {
            if(connection.State == ConnectionState.Closed)
            {
                connection.Open();
            }
        }
        public void closeConnection()
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }

    }

pls help me, I'm just a newbie in database, source and very confusing rn :((( I use mysql.data version 8.0.16.0 phpmyadmin version 4.9.2



Solution 1:[1]

For MySQL, the connection string should read Server instead of Data Source which is a keyword for MS SQL Server. See also: https://www.connectionstrings.com/mysql-connector-net-mysqlconnection/

You mention you are new to database development so I'd like to give you 2 tips:

  • Be very careful with posting the address and credentials to your database to the internet (StackOverflow, Github). In this case it looks like your credentials are harmless as the database is only reachable locally, but be mindful of this.
  • You're storing user data in a database. Be mindful of data security. It is considered essential to not store the passwords in their clear form, so use a form of hashing. But other user data is also privacy sensitive, so make sure your database is secured and your application does not lightly give access to user's data.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Simmetric