{"record":{"id":"6445645ec8bdb863","repo":"TechnitiumSoftware/DnsServer","slug":"the-connectionstring-parameter-must-not-define-644564","errorCode":null,"errorMessage":"The 'connectionString' parameter must not define 'Database'. Configure the 'databaseName' parameter above instead.","messagePattern":"The 'connectionString' parameter must not define 'Database'\\. Configure the 'databaseName' parameter above instead\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Apps/QueryLogsPostgreSqlApp/App.cs","lineNumber":372,"sourceCode":"\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 = @$\"\nCREATE TABLE IF NOT EXISTS dns_logs\n(\n    dlid SERIAL PRIMARY KEY,","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/QueryLogsPostgreSqlApp/App.cs#L354-L390","documentation":"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).","triggerScenarios":"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};\").","commonSituations":"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.","solutions":["Delete the 'Database=...' pair from 'connectionString', leaving Host/Port/Username/Password/etc.","Specify the target schema through the 'databaseName' parameter (default 'DnsQueryLogs').","Confirm the trimmed string has no 'Database=' substring remaining."],"exampleFix":"// before\n\"connectionString\": \"Host=localhost;Database=DnsQueryLogs;Username=postgres;Password=pass;\"\n\n// after\n\"connectionString\": \"Host=localhost;Username=postgres;Password=pass;\",\n\"databaseName\": \"DnsQueryLogs\"","handlingStrategy":"validation","validationCode":"static void ValidatePostgresConnectionString(string cs)\n{\n    if (cs.Replace(\" \", \"\").Contains(\"Database=\", StringComparison.OrdinalIgnoreCase))\n        throw new InvalidOperationException(\n            \"connectionString must not contain 'Database='. The app appends it from databaseName.\");\n}\n\nValidatePostgresConnectionString(connectionString);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip any 'Database=' segment before saving config.","Document that NpgsqlDataSource receives ' Database={databaseName};' appended automatically.","Lint config files for forbidden keywords per database backend."],"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"}