{"record":{"id":"3ad34fc165afa04a","repo":"TechnitiumSoftware/DnsServer","slug":"please-specify-a-valid-connection-string-in-conne-3ad34f","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":"error","filePath":"Apps/QueryLogsPostgreSqlApp/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                _dataSource = NpgsqlDataSource.Create(_connectionString + $\" Database={_databaseName};\");\n\n                async Task ApplyConfig()\n                {\n                    if (enableLogging)\n                    {\n                        await using (NpgsqlConnection connection = await _dataSource.OpenConnectionAsync())\n                        {\n                            await using (NpgsqlCommand command = connection.CreateCommand())\n                            {\n                                command.CommandText = @$\"","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/QueryLogsPostgreSqlApp/App.cs#L351-L387","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a non-null 'connectionString' value to dnsApp.config, e.g. 'Host=localhost;Username=postgres;Password=pass;'.","Do NOT include 'Database=' in it (see error 42); the databaseName parameter handles that.","Restart/reload the DNS server app after saving the config so ApplyConfig re-runs."],"exampleFix":"// before\n\"databaseName\": \"DnsQueryLogs\",\n\"connectionString\": null\n\n// after\n\"databaseName\": \"DnsQueryLogs\",\n\"connectionString\": \"Host=localhost;Username=postgres;Password=pass;\"","handlingStrategy":"validation","validationCode":"static void EnsurePostgresConnectionString(string? cs)\n{\n    if (string.IsNullOrWhiteSpace(cs))\n        throw new InvalidOperationException(\n            \"'connectionString' is missing in config. Set a PostgreSQL connection string.\");\n}\n\nEnsurePostgresConnectionString(connectionString);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provide a config schema/template with connectionString marked required.","Fail fast at app startup with a clear message instead of letting the null reach ApplyConfig.","Use a deployment validation step that checks required config keys."],"tags":["postgresql","config","connection-string","querylogs-app"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}