gneric
gneric

Reputation: 3685

MySQL Connection from an IoT Edge Module

I use my machine as a simulated device.

I deployed a docker image as a module to the device where I want to connect to a MySQL instance.

But I have the following error:

Unable to connect to any of the specified MySQL hosts.

I build the connection like this:

public static MySqlConnection BuildConnection(MySqlProperties parameters)
{
    MySqlConnectionStringBuilder connString = new MySqlConnectionStringBuilder();
    connString.Server = parameters.Server;
    connString.Database = parameters.Database;
    connString.UserID = parameters.Username;
    connString.Password = parameters.Password;
    connString.Add("Allow User Variables", true);

    var connection = new MySqlConnection(connString.ToString());
    return connection;
}

and then execute

var conn = BuildConnection(props);
Console.WriteLine("opening connection to mysql ...");
conn.Open();
Console.WriteLine("Connection state: " + conn.State);

Is it possible to connect to that database ?

Upvotes: 1

Views: 402

Answers (2)

gneric
gneric

Reputation: 3685

The issue was that MySQL wasn't configured for remote connections.

Upvotes: 2

Vladislav
Vladislav

Reputation: 2982

I'm about to get deep in this topic. As far as my understandings are, this error is expected, because you have to install the MySQL server as a module on the Edge run-time.

This Microsoft documentation provides instructions on storing data on the Edge with SQL Server. It is written that the same should work for MySQL, as well.

Upvotes: 0

Related Questions