ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

Nischay 125 Reputation points
2026-03-27T01:32:26.2666667+00:00

Hello,

We have a dashboard running on Azure App Service, connected to an Azure MySQL database. Earlier today, we experienced a connection issue that was resolved after restarting the server. Below are the relevant PHP (Laravel) logs:

2026-03-26 22:27:26] production.ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. {"exception":"[object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. at C:\\home\\site\\wwwroot\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connectors\\Connector.php:70) [stacktrace] [2026-03-26 22:27:29] production.ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: select * from `classes` where `join_code` = ios_first_run) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002):

We also observed a CPU spike on the SQL database around the same time (screenshot attached).

image

Any suggestions or advise on what might have caused this issue, and any steps we can take to prevent it in the future?

Azure Database for MySQL

1 answer

Sort by: Most helpful
  1. Christos Panagiotidis 3,551 Reputation points
    2026-07-21T12:39:27.14+00:00

    The PDO 2002 message confirms the App Service could not open a TCP connection to MySQL, but it does not prove the cause. Because the failure coincided with a CPU spike and cleared after restart, resource saturation, connection exhaustion, or a transient restart/failover are the leading possibilities.

    In Azure Monitor, correlate 22:27 UTC with Host CPU, Memory, Storage IO, Active Connections, Total Connections, and Aborted Connections. Check Resource Health and the Activity Log for maintenance or failover. Enable MySQL error and slow-query logs, then inspect statements running immediately before the spike. Verify the application uses the server FQDN, connection pooling, finite timeouts, and retry logic with exponential backoff. Optimize slow queries and scale compute if CPU remains sustained. If this recurs without a matching metric or log event, open Microsoft Support with the UTC timestamp, server name, and relevant logs.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.