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
Use
MySqlCommand cmd = new MySqlCommand("SHOW DATABASES;", conexionBD);
To get all the databbases stored in your server;
User contributions licensed under CC BY-SA 3.0