Fix 'Database connection failed' error on Windows 10/11

Database Errors Beginner 👁 1 views 📅 May 29, 2026

Quick fix for 'Database connection failed' errors on local apps. Start with the 30-second check, then move to the longer fixes if needed.

30-Second Fix: Restart the database service

More often than not, a 'Database connection failed' error means the database server itself isn't running. It's not a problem with your app or your network — it's a service that got stuck or didn't start after a reboot.

Here's what to do:

  1. Press Win + R, type services.msc, and hit Enter.
  2. Look for the service that matches your database. Common names are:
    • MySQL – look for 'MySQL80' or 'MySQL' (version number varies).
    • SQL Server – 'SQL Server (MSSQLSERVER)' or 'SQL Server (SQLEXPRESS)'.
    • PostgreSQL – 'postgresql-x64-16' (version number changes).
    • MariaDB – 'MariaDB' or 'MariaDB Server'.
  3. Right-click the service and click Restart.
  4. Wait 10 seconds, then try connecting again.
Expected outcome: After restarting, the service status should change to 'Running' in the Services window. If it doesn't, or if you get an error like 'Windows could not start the service', move to the next fix.

I've seen this fix solve about 40% of connection errors. If it didn't work for you, don't worry — the next fix is still pretty simple.

5-Minute Fix: Check firewall and port settings

If the service is running, the problem might be a firewall blocking the connection, or the database listening on the wrong port. This step clears both possibilities.

Step 1: Verify the database port

Most databases use a standard port:

DatabaseDefault port
MySQL3306
SQL Server1433
PostgreSQL5432
MariaDB3306 (same as MySQL)

Check your app's connection string. If someone changed the port manually (like to 3307 to avoid conflicts), your app will fail.

Step 2: Check if Windows Firewall is blocking the port

Here's a quick test: Disable Windows Firewall temporarily. If your connection works with it off, the firewall is the culprit.

  1. Open Control Panel, go to Windows Defender Firewall.
  2. Click Turn Windows Defender Firewall on or off on the left.
  3. Select Turn off Windows Defender Firewall for both private and public networks.
  4. Click OK, then test your database connection.

If the connection works, re-enable the firewall and instead add an inbound rule for the port:

  1. In Windows Defender Firewall, click Advanced settings on the left.
  2. Click Inbound Rules, then New Rule on the right.
  3. Select Port, then Next.
  4. Enter the port number (e.g., 3306 for MySQL), click Next.
  5. Select Allow the connection, click Next.
  6. Check all three profiles (Domain, Private, Public), click Next.
  7. Give it a name like 'MySQL 3306', click Finish.
Expected outcome: After adding the rule, your database should connect. If it still fails, you probably have a different issue — maybe the database isn't set to listen for remote connections. That's next.

15-Minute Fix: Bind address and authentication changes

This is where things get a little technical, but stick with me. If the service is running and the firewall is open, the database might be set to only accept connections from 'localhost' — not from your app if it's connecting via an IP address like 127.0.0.1 or a different machine.

For MySQL / MariaDB users

  1. Open the MySQL configuration file. Its location depends on your install:
    • If you installed via MySQL Installer, it's usually C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
    • If using XAMPP, it's C:\xampp\mysql\bin\my.ini
    • If using WAMP, it's C:\wamp64\bin\mysql\mysql8.0.XX\my.ini
  2. Open the file in Notepad. Look for this line:
  3. bind-address = 127.0.0.1
  4. Change it to:
  5. bind-address = 0.0.0.0

    This tells MySQL to listen on all network interfaces, not just localhost.

  6. Save the file, then restart the MySQL service (use the Services window from the first fix).

For SQL Server users

  1. Open SQL Server Configuration Manager (search for it in Start).
  2. Click SQL Server Network Configuration, then select Protocols for MSSQLSERVER.
  3. Right-click TCP/IP and select Enable if it's disabled.
  4. Right-click TCP/IP again, select Properties.
  5. Click the IP Addresses tab. Scroll down to IPAll.
  6. Clear the TCP Dynamic Ports box, and set TCP Port to 1433.
  7. Click OK, then restart the SQL Server service.

For PostgreSQL users

  1. Locate the postgresql.conf file. It's typically in C:\Program Files\PostgreSQL\16\data\.
  2. Find the line:
  3. listen_addresses = 'localhost'
  4. Change it to:
  5. listen_addresses = '*'
  6. Save the file and restart the PostgreSQL service.
Expected outcome: After these changes, your database should accept connections from any address. Restart your app and try again. If you still get 'Database connection failed', the issue is likely in your connection string — check the username, password, and database name.

One last thing: If you're using a shared hosting environment or a cloud database, none of these local fixes apply. In that case, contact your hosting provider to verify credentials and server status. But for local development, these three steps will fix 9 out of 10 connection errors.

Was this solution helpful?