Database connection timed out

Hi

I am currently stuck on the databse connection.
My databse is MariaDB and I use heidiSQL as the interface. I already created a user, access rights, database and tables.

In my Database.cs i have following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MySql.Data.MySqlClient;

public class Database : MonoBehaviour
{
    private MySqlConnection connection;
    private string server;
    private string database;
    private string user;
    private string password;

    public void Database_Initialize()
    {
        server = "IP-ADDRESS";
        database = "DB_NAME";
        user = "USERNAME";
        password = "PASSWORD";

        string connectionString = "Server=IP-ADDRESS;Port=PORT;Database=DB_NAME;Uid=USERNAME;Pwd=PASSWORD;";
        MySqlConnection connection = new MySqlConnection(connectionString);

        connection.Open();

        string query = "INSERT INTO user (UserName) VALUES ('User1')";
        MySqlCommand command = new(query, connection);

        command.CommandTimeout = 60;

        MySqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            // Access data using reader["columnname"]
        }
        reader.Close();

        connection.Close();
    }
}

When i run the script i get error:
TimeoutException: The operation has timed out. Rethrow as MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. MySql.Data.Common.StreamCreator.GetTcpStream (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings, MySql.Data.Common.MyNetworkStream& networkStream) (at <13314bc2115d4bd2a5d896df29fb7179>:0)

I downloaded my *MySQL.Data.dll file from the official website: https://dev.mysql.com/downloads/connector/net/

  • I also attached it to this thread in the “MySql.Data.zip”

8956368–1229964–MySql.Data.zip (576 KB)

RESOLVED c# - Unity HeidiSQL Connection timed out - Stack Overflow