J'utilise :
if (connection.State != ConnectionState.Open)
{
OpenConnection();
}
y
private bool OpenConnection()
{
try
{
connection.Open();
return true;
}
catch (MySqlException ex)
{
//When handling errors, you can your application's response based
//on the error number.
//The two most common error numbers when connecting are as follows:
//0: Cannot connect to server.
//1045: Invalid user name and/or password.
switch (ex.Number)
{
case 0:
Console.WriteLine("Cannot connect to server. Contact administrator");
Console.Read();
break;
case 1045:
Console.WriteLine("Invalid username/password, please try again");
Console.Read();
break;
}
return false;
}
}
Je reçois toujours System.InvalidOperationException: The connection is already open
. cela n'a pas de sens car je vérifie si c'est déjà ouvert.
Merci d'avance.