TechnitiumSoftware/DnsServer · error · Exception

Please specify a valid connection string in 'connectionStrin

Error message

Please specify a valid connection string in 'connectionString' parameter.

What it means

QueryLogsPostgreSqlApp requires a PostgreSQL connection string to reach the server. The 'connectionString' config property is read with a null default, and this error fires when it is absent or explicitly null. Without it the app cannot build the NpgsqlDataSource used to persist DNS query logs.

Source

Thrown at Apps/QueryLogsPostgreSqlApp/App.cs:369

            try
            {
                _dnsServer = dnsServer;

                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 = @$"

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Add a non-null 'connectionString' value to dnsApp.config, e.g. 'Host=localhost;Username=postgres;Password=pass;'.
  2. Do NOT include 'Database=' in it (see error 42); the databaseName parameter handles that.
  3. Restart/reload the DNS server app after saving the config so ApplyConfig re-runs.

Example fix

// before
"databaseName": "DnsQueryLogs",
"connectionString": null

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

Strategy: validation

Validate before calling

static void EnsurePostgresConnectionString(string? cs)
{
    if (string.IsNullOrWhiteSpace(cs))
        throw new InvalidOperationException(
            "'connectionString' is missing in config. Set a PostgreSQL connection string.");
}

EnsurePostgresConnectionString(connectionString);

Prevention

When it happens

Trigger: ApplyConfig is invoked with a JSON config that omits the 'connectionString' property entirely, or sets it to null. The null-check throws before any database interaction occurs.

Common situations: Fresh install of the QueryLogsPostgreSqlApp where the config template was not filled in; a config edit that deleted the connectionString line; or a deployment script that wrote an empty value.

Related errors


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