I have this code:
using MySql.Data.MySqlClient;
namespace DigitalWilds.Models
{
public class DatabaseConn
{
public string status = "failed";
MySqlConnection conn;
public string connectionString;
public DatabaseConn()
{
string webHost = "(host IP)";
string dataBase = "DB";
string userID = "UID";
string password = "PASS";
string port = "3306";
connectionString = "Server="+webHost+";Port="+port+";Database=" + dataBase+ ";Uid ="+userID+";Pwd="+password;
try
{
conn = new MySqlConnection();
conn.ConnectionString = connectionString;
conn.Open();
status = "success";
conn.Close(); conn.Dispose();
}
catch (MySqlException ex)
{
status = ex.Message;
}
}
}
}
The error message is :
"Unable to connect to any of the specified MySQL hosts."
I am trying to initiate a connection to my DB server. I keep ending up in the catch block. I have used, almost ver batum,
the code from here:
https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html.
I now use the string format from this site:
https://www.connectionstrings.com/mysql/
I am spitting out both status and connectionString. status comes back as "Unable to connect to any of the specified MySQL hosts." and connectionString comes back as what I expect it.
I have tried with and without the port, I even also tried ip:port just to see.
What am I doing wrong?
Edit:
It was pointed out that I can use Exception.ToString. Doing so gives:
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.TimeoutException: The operation has timed out. at MySql.Data.Common.StreamCreator.GetTcpStreamAsync(MySqlConnectionStringBuilder settings, CancellationToken cancellationToken, Boolean execAsync) at MySql.Data.Common.StreamCreator.GetStreamAsync(MySqlConnectionStringBuilder settings, CancellationToken cancellationToken, Boolean execAsync) at MySql.Data.MySqlClient.NativeDriver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.NativeDriver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.Driver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.Driver.CreateAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.Driver.CreateAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnectionAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.MySqlPool.GetPooledConnectionAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.MySqlPool.TryToGetDriverAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.MySqlPool.GetConnectionAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Boolean execAsync, CancellationToken cancellationToken) at MySql.Data.MySqlClient.MySqlConnection.Open() at DigitalWilds.Models.DatabaseConn..ctor() in C:\Users\Me\source\repos\DigitalWilds\Models\DatabaseConn.cs:line 29