TechnitiumSoftware/DnsServer · critical · Exception

Please specify a valid connection string in 'connectionStrin

Error message

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

What it means

Thrown by QueryLogsMySqlApp when the 'connectionString' property is absent from its config JSON. The app needs a MySQL connection string to log queries; a missing one is fatal and raises a base Exception. Note the next guard also rejects a connection string that contains 'Database=' — the database name must come from the separate 'databaseName' parameter.

Source

Thrown at Apps/QueryLogsMySqlApp/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 += ";";

                async Task ApplyConfig()
                {
                    if (enableLogging)
                    {
                        await using (MySqlConnection connection = new MySqlConnection(_connectionString))
                        {
                            await connection.OpenAsync();

                            await using (MySqlCommand command = connection.CreateCommand())
                            {
                                command.CommandText = @$"

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Add a 'connectionString' key to the QueryLogsMySqlApp config with a valid MySQL connection string (server, user, password).
  2. Do NOT include 'Database=' in the connection string — set the database via the 'databaseName' parameter instead.
  3. Verify MySQL credentials and network reachability from the DNS server host.
  4. Reload the app and confirm query logging starts.

Example fix

// before
{ "enableLogging": true, "databaseName": "DnsQueryLogs" }
// after
{ "enableLogging": true, "databaseName": "DnsQueryLogs", "connectionString": "Server=mysql.example;User Id=dns;Password=secret;" }
Defensive patterns

Strategy: validation

Validate before calling

_connectionString = jsonConfig.GetPropertyValue("connectionString", null);
if (string.IsNullOrWhiteSpace(_connectionString))
    throw new ConfigValidationException("QueryLogsMySqlApp requires a non-empty 'connectionString'.");
if (_connectionString.Replace(" ","").Contains("Database=", StringComparison.OrdinalIgnoreCase))
    throw new ConfigValidationException("'connectionString' must not contain 'Database='; use the 'databaseName' parameter.");

Prevention

When it happens

Trigger: QueryLogsMySqlApp config lacks the 'connectionString' key, e.g. {"enableLogging":true,"databaseName":"DnsQueryLogs"} with no connection string. GetPropertyValue returns null and the explicit null check throws.

Common situations: New MySQL logging setup where the operator configured enableLogging/databaseName but forgot the connection string, or a templated config where the placeholder was never substituted.

Related errors


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