I can’t connect my C# Win Form app with MariaDB.
For litle context I need to deploy my C# Winform App. I success to create a setup.exe and now I need to deploy the DB. I have create a VPS and create the great database with a simple script SQL create by phpmyadmin. I’m almost sure that my connection string and connection credentials are OK
I use the extension MySQL Connector
Here my code :
private string connectionString = ConfigurationManager.ConnectionStrings["localhost"].ConnectionString;
public string GetHashForAuthentification(string login_m)
{
string hash = null;
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
conn.Open();
string query = "SELECT password_m FROM medecin WHERE login_m = @login_m;";
using (MySqlCommand command = new MySqlCommand(query, conn))
{
command.Parameters.AddWithValue("@login_m", login_m);
using (MySqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
hash = reader.GetString("password_m");
}
}
}
conn.Close();
}
return hash;
}
When I try to login by the debug mode from Visual Studio, I have this error who spawn at “conn.Open()” : System.InvalidCastException: ‘Object cannot be cast from DBNull to other types.’
Have you some solution for my problem ? May be my MariaDB Version ?
Thanks…
I try to change the user of the database, try to change the connection string
user24646051 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3