MySql.Data.MySqlClient.MySqlException(0x80004005) you have an error in your SQL syntax

-1

I have this error when I try to create a connection with SQL and Visual Studio 2019.

namespace Visual_SQL
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {    
        }

        private void BtnConnection_Click(object sender, EventArgs e)
        {
            string servidor = TXTServer.Text;
            string puerto = TXTPort.Text;
            string usuario = TXTUser.Text;
            string contraseƱa = TXTPassword.Text;
            string dato = "";

            string cadenaConexion = "server=" + servidor + "; port=" + puerto + "; user id=" + usuario + "; password=" + contraseƱa + "; database=mysql;";

            MySqlConnection conexionBD = new MySqlConnection(cadenaConexion); 

            try    
            {                 
                conexionBD.Open();

                MySql.Data.MySqlClient.MySqlDataReader reader = null;

                MySqlCommand cmd = new MySqlCommand("Mostrar database", conexionBD);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    dato += reader.GetString(0) + "\n";    
                }
            }
            catch(MySqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            MessageBox.Show(dato);
        }
    }
}

If someone could help me

enter image description here

c#
mysql
visual-studio
asked on Stack Overflow Mar 25, 2020 by alejandro arevalo • edited Mar 25, 2020 by jmq

1 Answer

0

Use

MySqlCommand cmd = new MySqlCommand("SHOW DATABASES;", conexionBD);

To get all the databbases stored in your server;

answered on Stack Overflow Mar 25, 2020 by nbk

User contributions licensed under CC BY-SA 3.0