When connecting to my database I get a Connection Refused error
Validated on 9 Jul 2024 • Last edited on 15 Jul 2024
There are two types of Connection Refused
errors: refused for Hostname and for IP Address. Reference the following guides to identify your issue and troubleshoot:
Connection Refused (Hostname)
A Connection Refused (Hostname)
error occurs when:
- You use the wrong port in the connection string.
- You connect from a machine that is not in the database’s list of trusted sources.
If you are getting this error:
- Check that the port is correct in the connection string.
- Check that you have added the machine or resource you are connecting from to the database’s list of trusted sources. To check your database’s trusted sources, see the following guides for PostgreSQL, MySQL, Redis, MongoDB, Kafka, and OpenSearch.
Connection Refused (IP Address)
A Connection Refused (IP Address)
error occurs when:
- You use the wrong IP address in the connection string.
- Use the database’s private IP address in the connection string and try to connect from a Droplet that isn’t allowed to access the VPC network.
If you are getting this error:
- Check the IP address in the connection string or use the database’s hostname. We recommend using the hostname over the IP address because the IP address may change, but the hostname always remains the same.
- If you’re using the database’s private IP address, connect from a Droplet that meets the following criteria:
- The Droplet is on the same DigitalOcean account as the database.
- The Droplet is in the same datacenter region as the database.
- The Droplet resides in the same VPC network as the target Droplet. To check VPC networks, see the following guides for PostgreSQL, MySQL, Redis, MongoDB, Kafka, and OpenSearch.
Add your machine to the database cluster’s list of trusted sources.
Prepend your connection string with your database client.
Check for typos and formatting errors in the connection string.