C# cannot reach MySQL: connection attempt failed, no response in time
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 respondShort 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.
Fix it fast
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 33062Match what you see, then jump to its fix
- 1
telnet hangs and then times out, with no refusal messageA firewall or security group drops traffic to the MySQL portFix - 2
The server works locally but not from another hostMySQL listens only on the loopback address, or has networking offFix - 3
The port answers in telnet but connecting from .NET fails now and thenThe connection timeout is too short for a slow networkFix
- 1
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 respondSystem.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 33062Fix
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 tcp3Verify
telnet should now print a version string from the server.
telnet db.example.com 3306Confirmed by dev.mysql.com
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.03Verify
Connect from the app host.
mysqladmin -h db.example.com --port=3306 versionConfirmed by dev.mysql.com
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*.json2Fix
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=303Verify
Run the app and open a connection.
dotnet runConfirmed by mysqlconnector.net
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
EF Core logs 'An error occurred using the connection to database' with MySQL
Can't connect to MySQL server on 'host_name' (111)
This EF Core message is only a wrapper.
3 causes, each with a fixDatabases
DbContextOptionsBuilder has no UseMySql method
Cannot find the UseMysql method on DbContextOptions
UseMySql comes from a provider package, not from EF Core itself.
3 causes, each with a fixDatabases
There is already an open DataReader on the MySQL connection
The error appears inside a while (reader.Read()) loop
One MySQL connection runs one operation at a time.
3 causes, each with a fixDatabases
C# INSERT fails with 'Fatal error encountered during command execution'
MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution
A fatal error during command execution means the connection broke while the INSERT was in flight.
3 causes, each with a fixDatabases
MySqlException: Timeout expired in a .NET app
MySql.Data.MySqlClient.MySqlException: Timeout expired
Timeout expired means a wait ended before it finished.
3 causes, each with a fixDatabases
MySqlException: unable to connect to any of the specified MySQL hosts
Can't connect to MySQL server on 'host' (10061)
The connector could not open a TCP connection to the host and port in your connection string.
4 causes, each with a fix