TechnitiumSoftware/DnsServer · error · Exception

The 'connectionString' parameter must not define 'Database'.

Error message

The 'connectionString' parameter must not define 'Database'. Configure the 'databaseName' parameter above instead.

What it means

QueryLogsPostgreSqlApp splits server connection info ('connectionString') from the target schema ('databaseName'). Internally it appends ' Database={databaseName};' to the user's string when creating the NpgsqlDataSource, so a pre-existing 'Database=' would collide. This error fires when the connectionString contains a 'Database=' segment (space-stripped, case-insensitive match).

Source

Thrown at Apps/QueryLogsPostgreSqlApp/App.cs:372

                if (config is null)
                    throw new InvalidOperationException();

                using JsonDocument jsonDocument = JsonDocument.Parse(config, _jsonParseOptions);
                JsonElement jsonConfig = jsonDocument.RootElement;

                bool enableLogging = jsonConfig.GetPropertyValue("enableLogging", false);
                int maxQueueSize = jsonConfig.GetPropertyValue("maxQueueSize", 1000000);
                _maxLogDays = jsonConfig.GetPropertyValue("maxLogDays", 0);
                _maxLogRecords = jsonConfig.GetPropertyValue("maxLogRecords", 0);
                _databaseName = jsonConfig.GetPropertyValue("databaseName", "DnsQueryLogs");
                _connectionString = jsonConfig.GetPropertyValue("connectionString", null);

                if (_connectionString is null)
                    throw new Exception("Please specify a valid connection string in 'connectionString' parameter.");

                if (_connectionString.Replace(" ", "").Contains("Database=", StringComparison.OrdinalIgnoreCase))
                    throw new Exception("The 'connectionString' parameter must not define 'Database'. Configure the 'databaseName' parameter above instead.");

                if (!_connectionString.TrimEnd().EndsWith(';'))
                    _connectionString += ";";

                _dataSource = NpgsqlDataSource.Create(_connectionString + $" Database={_databaseName};");

                async Task ApplyConfig()
                {
                    if (enableLogging)
                    {
                        await using (NpgsqlConnection connection = await _dataSource.OpenConnectionAsync())
                        {
                            await using (NpgsqlCommand command = connection.CreateCommand())
                            {
                                command.CommandText = @$"
CREATE TABLE IF NOT EXISTS dns_logs
(
    dlid SERIAL PRIMARY KEY,

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Delete the 'Database=...' pair from 'connectionString', leaving Host/Port/Username/Password/etc.
  2. Specify the target schema through the 'databaseName' parameter (default 'DnsQueryLogs').
  3. Confirm the trimmed string has no 'Database=' substring remaining.

Example fix

// before
"connectionString": "Host=localhost;Database=DnsQueryLogs;Username=postgres;Password=pass;"

// after
"connectionString": "Host=localhost;Username=postgres;Password=pass;",
"databaseName": "DnsQueryLogs"
Defensive patterns

Strategy: validation

Validate before calling

static void ValidatePostgresConnectionString(string cs)
{
    if (cs.Replace(" ", "").Contains("Database=", StringComparison.OrdinalIgnoreCase))
        throw new InvalidOperationException(
            "connectionString must not contain 'Database='. The app appends it from databaseName.");
}

ValidatePostgresConnectionString(connectionString);

Prevention

When it happens

Trigger: ApplyConfig receives a 'connectionString' containing 'Database=...' (any casing, any spacing). The guard throws because the app injects the database itself via NpgsqlDataSource.Create(_connectionString + $" Database={_databaseName};").

Common situations: Reusing a PostgreSQL connection string from pgAdmin, DBeaver, or another .NET app that includes the database, and pasting it into dnsApp.config without trimming the Database keyword.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/6445645ec8bdb863. Report an issue: GitHub.