DB connection fails on startup - Server=localhost invalid in Docker #1

Closed
opened 2026-03-27 21:40:17 +02:00 by iAdrian · 0 comments
Owner

Problem

On startup, the server crashes immediately with a DB connection error.

NHibernate (the ORM used for DB access) tries to connect to 127.0.0.1:5432 (localhost) but in Docker, the database is only reachable via its service name diiis-na-db.

Error

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Npgsql.NpgsqlException: Failed to connect to 127.0.0.1:5432 System.Net.Sockets.SocketException: Connection refused

Root Cause

The connection strings in the config files have Server=localhost hardcoded, which does not resolve inside a Docker network.

Affected files:

  • src/DiIiS-NA/database.Account.config
  • src/DiIiS-NA/database.Worlds.config

Fix

Change Server=localhostServer=diiis-na-db in both files:

<!-- Before -->
Server=localhost;Database=diiis;User ID=postgres;Password=postgres

<!-- After -->
Server=diiis-na-db;Database=diiis;User ID=postgres;Password=postgres

Environment

- Docker Compose
- PostgreSQL 17 (container: diiis-na-db)
## Problem On startup, the server crashes immediately with a DB connection error. NHibernate (the ORM used for DB access) tries to connect to `127.0.0.1:5432` (`localhost`) but in Docker, the database is only reachable via its service name `diiis-na-db`. ## Error ``` FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Npgsql.NpgsqlException: Failed to connect to 127.0.0.1:5432 System.Net.Sockets.SocketException: Connection refused ``` ## Root Cause The connection strings in the config files have `Server=localhost` hardcoded, which does not resolve inside a Docker network. **Affected files:** - `src/DiIiS-NA/database.Account.config` - `src/DiIiS-NA/database.Worlds.config` ## Fix Change `Server=localhost` → `Server=diiis-na-db` in both files: ```xml <!-- Before --> Server=localhost;Database=diiis;User ID=postgres;Password=postgres <!-- After --> Server=diiis-na-db;Database=diiis;User ID=postgres;Password=postgres Environment - Docker Compose - PostgreSQL 17 (container: diiis-na-db)
iAdrian changed title from DB connection fails on startup - Server=localhost invalid in Docker #1 to DB connection fails on startup - Server=localhost invalid in Docker 2026-03-27 22:11:50 +02:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Gaming/blizzless-diiis#1
No description provided.