I'm creating a Windows Forms App (.NET Framework) and trying to connect to a MySQL Database on my LAN.
The code I'm using is:
private void button1_Click(object sender, EventArgs e)
{
connString = $"SERVER={server}; DATABASE={database};
UID={username}; PASSWORD={password}";
try{
conn = new MySqlConnection();
conn.ConnectionString = connString;
conn.Open();
MessageBox.Show("Connected.");
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
When I step through the code and it gets to
conn.Open();
I receive the following error:
System.InvalidCastException HResult=0x80004002 Message=Object cannot be cast from DBNull to other types.
However, the database opens and I can Add, Delete and Query the database.
Anyone tell this novice what is going on?
What I have tried:
I've Googled the error and none of it seems to make sense (to me) as
the database connection is fine.