❔ My first time using mySql workbench with c#

im trying to connect mysql to my HabitTrackerand i keep getting "Unable to connect to any of the specified MySql hosts." in the console. Not 100% on what im doing

static void Main(string[] args)
        {
            MySql.Data.MySqlClient.MySqlConnection conn;
            string connectionString = @"Data Source=HabitTracker.db";

            try
            {
                conn = new MySql.Data.MySqlClient.MySqlConnection();
                conn.ConnectionString = connectionString;
                conn.Open();
                var tableCmd = conn.CreateCommand();

                tableCmd.CommandText = 
                    @"CREATE TABLE IF NOT EXISTS drinking_water(
                        Id Integer PRIMARY KEY AUTOINCREMENT,
                        Date_Of DATE,
                        Quantity INTEGER
                        )";
                tableCmd.ExecuteNonQuery();
                conn.Close();
            }
            catch(MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Was this page helpful?