Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

C# cannot reach MySQL: connection attempt failed, no response in time

ErrorA connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Short answer

SocketError 10060 means the connection attempt timed out, or the host did not respond. Nothing answered on that address and port in time. Check that the port is reachable from the app host, then look at the MySQL bind address and the firewall. Raise Connection Timeout only if the network is truly slow.

  • Applies to MySQL 8.4, MySqlConnector 2.x, .NET 8
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Test the raw TCP port from the machine that runs the app, not from your laptop.

    telnet db.example.com 3306
  2. 2Match what you see, then jump to its fix

    1. 1telnet hangs and then times out, with no refusal messageA firewall or security group drops traffic to the MySQL portFix
    2. 2The server works locally but not from another hostMySQL listens only on the loopback address, or has networking offFix
    3. 3The port answers in telnet but connecting from .NET fails now and thenThe connection timeout is too short for a slow networkFix

What does the error look like?

  • A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
  • System.Net.Sockets.SocketException (10060)

Cause 1 of 3

A firewall or security group drops traffic to the MySQL port

1Check

A blocked port gives a timeout instead of a quick refusal. The MySQL manual lists the firewall on port 3306 (or your configured port) as a cause.

telnet db.example.com 3306

2Fix

Allow the app host's address on the MySQL port in the server firewall and in any cloud security group.

# example with ufw; use your own firewall's rule for the same thing
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcp

3Verify

telnet should now print a version string from the server.

telnet db.example.com 3306

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 3

MySQL listens only on the loopback address, or has networking off

1Check

With bind_address=127.0.0.1 only local connections are accepted, and skip_networking disables TCP/IP completely.

mysql -u root -p -e "SHOW VARIABLES LIKE 'bind_address'; SHOW VARIABLES LIKE 'skip_networking';"

2Fix

Set bind_address to an address clients can reach and keep skip_networking off, then restart the server.

# my.cnf
[mysqld]
bind_address = 0.0.0.0

3Verify

Connect from the app host.

mysqladmin -h db.example.com --port=3306 version

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 3

The connection timeout is too short for a slow network

1Check

MySqlConnector waits 15 seconds by default (Connection Timeout) before a connect fails.

grep -R -n -i "timeout" appsettings*.json

2Fix

Raise Connection Timeout in the connection string if the link is genuinely slow, for example a VPN. Do not use it to hide a blocked port.

Server=db.example.com;Port=3306;Database=app;User ID=app;Password=...;Connection Timeout=30

3Verify

Run the app and open a connection.

dotnet run

Confirmed by mysqlconnector.net

Did this fix it?

How do I stop it coming back?

  • Keep the database host and port in configuration and test them in the deploy pipeline.
  • Use a private network or an allow-list instead of opening port 3306 to everyone.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.