{"record":{"id":"77be592f75b26cf0","repo":"TechnitiumSoftware/DnsServer","slug":"the-connectionstring-parameter-must-not-define","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/QueryLogsMySqlApp/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                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 = @$\"\nCREATE DATABASE IF NOT EXISTS `{_databaseName}`;\n\nUSE `{_databaseName}`;","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/QueryLogsMySqlApp/App.cs#L354-L390","documentation":"The QueryLogsMySqlApp stores MySQL connection details across two separate config parameters: 'connectionString' (server/auth) and 'databaseName' (target schema). This error fires when the connectionString itself already contains a 'Database=' segment, because the app manages the database name independently and would otherwise double-specify it. The check strips spaces then does a case-insensitive search for 'Database='.","triggerScenarios":"Calling ApplyConfig with a JSON config whose 'connectionString' value includes a 'Database=...' key-value pair (e.g. 'Server=localhost;Database=DnsQueryLogs;Uid=root;'). The space-stripped case-insensitive Contains matches even 'Database =' or ' database='.","commonSituations":"Copying a working MySQL connection string from another tool (Workbench, EF Core, another app) that baked the schema into the string, then pasting it into the dnsApp.config connectionString field without removing the Database segment.","solutions":["Remove the 'Database=...' pair from the 'connectionString' config value, keeping only server/auth options (Server, Port, Uid, Pwd, etc.).","Set (or keep) the desired schema via the 'databaseName' config parameter, which defaults to 'DnsQueryLogs'.","Ensure no stray 'Database=' substring remains after editing, including spaces like 'Database ='."],"exampleFix":"// before (dnsApp.config)\n\"connectionString\": \"Server=localhost;Database=DnsQueryLogs;Uid=root;Pwd=pass;\"\n\n// after\n\"connectionString\": \"Server=localhost;Uid=root;Pwd=pass;\",\n\"databaseName\": \"DnsQueryLogs\"","handlingStrategy":"validation","validationCode":"// Run before ApplyConfig / before writing dnsApp.config\nstatic void ValidateMySqlConnectionString(string cs)\n{\n    if (cs.Replace(\" \", \"\").Contains(\"Database=\", StringComparison.OrdinalIgnoreCase))\n        throw new InvalidOperationException(\n            \"connectionString must not contain 'Database='. Use the databaseName parameter.\");\n}\n\nValidateMySqlConnectionString(connectionString);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat connectionString as server/auth-only; never paste a full string from another tool unchecked.","Keep databaseName as the single source of truth for the schema in config templates.","Add a CI check that greps dnsApp.config for 'Database=' inside connectionString."],"tags":["mysql","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"}