{"record":{"id":"e090232f909ab6cf","repo":"TechnitiumSoftware/DnsServer","slug":"please-specify-a-valid-connection-string-in-conne","errorCode":null,"errorMessage":"Please specify a valid connection string in 'connectionString' parameter.","messagePattern":"Please specify a valid connection string in 'connectionString' parameter\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Apps/QueryLogsMySqlApp/App.cs","lineNumber":369,"sourceCode":"            try\n            {\n                _dnsServer = dnsServer;\n\n                if (config is null)\n                    throw new InvalidOperationException();\n\n                using JsonDocument jsonDocument = JsonDocument.Parse(config, _jsonParseOptions);\n                JsonElement jsonConfig = jsonDocument.RootElement;\n\n                bool enableLogging = jsonConfig.GetPropertyValue(\"enableLogging\", false);\n                int maxQueueSize = jsonConfig.GetPropertyValue(\"maxQueueSize\", 1000000);\n                _maxLogDays = jsonConfig.GetPropertyValue(\"maxLogDays\", 0);\n                _maxLogRecords = jsonConfig.GetPropertyValue(\"maxLogRecords\", 0);\n                _databaseName = jsonConfig.GetPropertyValue(\"databaseName\", \"DnsQueryLogs\");\n                _connectionString = jsonConfig.GetPropertyValue(\"connectionString\", null);\n\n                if (_connectionString is null)\n                    throw new Exception(\"Please specify a valid connection string in 'connectionString' parameter.\");\n\n                if (_connectionString.Replace(\" \", \"\").Contains(\"Database=\", StringComparison.OrdinalIgnoreCase))\n                    throw new Exception(\"The 'connectionString' parameter must not define 'Database'. Configure the 'databaseName' parameter above instead.\");\n\n                if (!_connectionString.TrimEnd().EndsWith(';'))\n                    _connectionString += \";\";\n\n                async Task ApplyConfig()\n                {\n                    if (enableLogging)\n                    {\n                        await using (MySqlConnection connection = new MySqlConnection(_connectionString))\n                        {\n                            await connection.OpenAsync();\n\n                            await using (MySqlCommand command = connection.CreateCommand())\n                            {\n                                command.CommandText = @$\"","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/QueryLogsMySqlApp/App.cs#L351-L387","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a 'connectionString' key to the QueryLogsMySqlApp config with a valid MySQL connection string (server, user, password).","Do NOT include 'Database=' in the connection string — set the database via the 'databaseName' parameter instead.","Verify MySQL credentials and network reachability from the DNS server host.","Reload the app and confirm query logging starts."],"exampleFix":"// before\n{ \"enableLogging\": true, \"databaseName\": \"DnsQueryLogs\" }\n// after\n{ \"enableLogging\": true, \"databaseName\": \"DnsQueryLogs\", \"connectionString\": \"Server=mysql.example;User Id=dns;Password=secret;\" }","handlingStrategy":"validation","validationCode":"_connectionString = jsonConfig.GetPropertyValue(\"connectionString\", null);\nif (string.IsNullOrWhiteSpace(_connectionString))\n    throw new ConfigValidationException(\"QueryLogsMySqlApp requires a non-empty 'connectionString'.\");\nif (_connectionString.Replace(\" \",\"\").Contains(\"Database=\", StringComparison.OrdinalIgnoreCase))\n    throw new ConfigValidationException(\"'connectionString' must not contain 'Database='; use the 'databaseName' parameter.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide a 'connectionString' in the QueryLogsMySqlApp config.","Never embed 'Database=' in the string — use the separate 'databaseName' parameter.","Store the connection string via a secrets manager rather than hand-editing JSON."],"tags":["config","query-logs","mysql","connection-string","startup"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}