If an error occurs when connecting to a database, first check that the connection data (host, database name, database username and password) are correct. You can find out the current data of access to the database by instructions.
If the data is correct, but there is still no access, the reason may be that the limit of connections to the database has been exhausted. As a rule, in such situations, access to the database periodically appears and disappears. The risk of such a problem is higher with intensive external connections... To remedy the situation, you need to find out the possible reasons why a large number of connections to the database can be created and eliminate them.