Reader Questions About Connection Errors and Connection Strings
Your first attempt to connect an app to a database server often ends in an error. These are the questions learners send most, with what each message usually means and what to check first.
"Connection refused"
What does it mean?
Your program reached the computer, but nothing was listening on that port. Usually the database server is not running, is listening on a different port, or only accepts connections from its own machine.
What do I check?
- Is the database running? Start it, or check its status in your operating system's service manager or Docker.
- Is the port right? PostgreSQL usually uses 5432, MySQL 3306, SQL Server 1433.
- Is the host right?
localhostmeans "this computer".
"Password authentication failed" or "Access denied"
What does it mean?
The server answered, but did not accept the user name and password.
What do I check?
- spelling and capital letters in the user name
- the password, including any characters that need encoding in a URL (
@becomes%40) - that the user exists on that server, and is allowed to connect from where you are
- that you are not mixing up the database's users with your computer's login
"Could not translate host name" or "Unknown host"
The host name in your connection string cannot be found. Check for typos. If you are inside a Docker container, remember that localhost means the container itself; use the other container's service name instead.
"Database does not exist" or "Unknown database"
You logged in to the server, but the database name at the end of the string is not there. One server can hold several databases. List them (\l in PostgreSQL's psql, SHOW DATABASES; in MySQL) and check the name, or create it.
"Timeout" or the program just hangs
What does it mean?
Your connection attempt is not getting any answer at all. Often a firewall is silently dropping it, or the host address points somewhere unreachable.
What do I check?
- for hosted databases, whether your IP address must be added to an allow-list in the provider's settings
- whether you are on a network that blocks database ports
- that you are using the public address, not an internal one, when connecting from outside
Questions about the string itself
Why does my password with an @ break everything?
In URL-style connection strings, @ separates the login from the host. Encode it as %40, or pass the password as a separate setting if your library allows it.
Should the password be in the string at all?
Keep the whole string in an environment variable, not in your code. See how to keep a connection string in an environment variable.
Do I need SSL options?
For hosted databases, usually yes; many providers require encrypted connections. Their documentation gives the exact option, such as sslmode=require for PostgreSQL.
A checklist when you are stuck
| Question | Quick test |
|---|---|
| Is the server running? | Connect with the database's own command-line tool |
| Is the address right? | Read each part of the string slowly |
| Are the credentials right? | Log in with the same details in a graphical tool |
| Is the network open? | Try from the same machine as the database |
To read every part of a string confidently, see reading a connection string piece by piece.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.
This is a static page of sample discussion topics. There is no live forum, membership or user community on this site.