Diagnosing Your First Can't Connect Error

Almost everyone's first database app fails to connect at least once. The error messages look scary, but they usually point to one of five simple causes. Work through them in order, and keep the exact error text handy, because it holds most of the clues.

Check 1: is the database server running?

SQLite is just a file, so there is no server to start. MySQL, PostgreSQL and SQL Server are servers: programs that must be running before anything can connect.

Symptom: messages like "connection refused" or "could not connect to server".

What to try: start the database service, or check that your Docker container or cloud database is running. If you use a hosted database, look at its status page in your provider's dashboard.

Check 2: is the address right?

The host is the computer the database runs on. On your own machine it is usually localhost or 127.0.0.1.

Symptom: "could not translate host name", "unknown host", or a long wait followed by a timeout.

What to try: copy the host name again from your provider's dashboard. Watch for extra spaces and typos.

Check 3: is the port right?

The port is like a door number on that computer. Common defaults:

DatabaseDefault port
PostgreSQL5432
MySQL and MariaDB3306
SQL Server1433

Symptom: "connection refused" even though the server is running.

What to try: check which port the server actually uses; hosted databases sometimes use a different one.

Check 4: are the login details right?

Symptom: "password authentication failed", "access denied for user", or "login failed".

What to try:

Check 5: is the right driver installed?

A driver is the library your programming language uses to talk to the database, for example psycopg for PostgreSQL in Python or mysql2 in Node.js.

Symptom: "module not found", "no suitable driver", or "unknown dialect".

What to try: install the driver for your exact database and language, and check you are running the code in the same environment where you installed it.

A tiny test script

Before debugging a whole app, test the connection alone. In Python with SQLite, for example:

import sqlite3
conn = sqlite3.connect("test.db")
print(conn.execute("SELECT 1").fetchone())
conn.close()

If the tiny script works and your app does not, the problem is in how the app reads its settings, often a missing environment variable.

When to ask for help

If all five checks pass, copy the full error message and your connection string with the password removed, and ask in a beginner-friendly forum or your course's help channel. Our page on connection errors and connection strings answers several follow-up questions.

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.