{"record":{"id":"a1b5515c6f336e13","repo":"TechnitiumSoftware/DnsServer","slug":"the-connectionstring-parameter-must-not-define-a1b551","errorCode":null,"errorMessage":"The 'connectionString' parameter must not define 'Initial Catalog'. Configure the 'databaseName' parameter above instead.","messagePattern":"The 'connectionString' parameter must not define 'Initial Catalog'\\. Configure the 'databaseName' parameter above instead\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Apps/QueryLogsSqlServerApp/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.Contains(\"Initial Catalog\", StringComparison.OrdinalIgnoreCase))\n                    throw new Exception(\"The 'connectionString' parameter must not define 'Initial Catalog'. 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 (SqlConnection connection = new SqlConnection(_connectionString))\n                        {\n                            await connection.OpenAsync();\n\n                            await using (SqlCommand command = connection.CreateCommand())\n                            {\n                                command.CommandText = @$\"\nIF NOT EXISTS(SELECT * FROM sys.databases WHERE name = '{_databaseName}')\nBEGIN\n    CREATE DATABASE \"\"{_databaseName}\"\";","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/QueryLogsSqlServerApp/App.cs#L354-L390","documentation":"QueryLogsSqlServerApp separates server coordinates ('connectionString') from the target schema ('databaseName'). SQL Server uses 'Initial Catalog' to denote the database, and this guard rejects any connectionString containing that keyword (case-insensitive). The app supplies the database itself, so a user-supplied Initial Catalog would conflict.","triggerScenarios":"ApplyConfig gets a 'connectionString' that includes 'Initial Catalog=...' (any casing). The case-insensitive Contains match throws. Note: unlike the MySQL/Postgres checks, this one does NOT strip spaces, so 'InitialCatalog' is caught but oddly-spaced variants behave per the literal substring.","commonSituations":"Pasting a SQL Server connection string from SSMS, connectionstrings.com, or EF Core that baked 'Initial Catalog' into it, into the dnsApp.config without removing that keyword.","solutions":["Remove the 'Initial Catalog=...' pair from 'connectionString', keeping Server/Auth/Encrypt options.","Set the schema via the 'databaseName' parameter (default 'DnsQueryLogs').","Verify no 'Initial Catalog' substring remains before saving."],"exampleFix":"// before\n\"connectionString\": \"Server=localhost;Initial Catalog=DnsQueryLogs;User Id=sa;Password=pass;\"\n\n// after\n\"connectionString\": \"Server=localhost;User Id=sa;Password=pass;TrustServerCertificate=true;\",\n\"databaseName\": \"DnsQueryLogs\"","handlingStrategy":"validation","validationCode":"static void ValidateSqlServerConnectionString(string cs)\n{\n    if (cs.Contains(\"Initial Catalog\", StringComparison.OrdinalIgnoreCase))\n        throw new InvalidOperationException(\n            \"connectionString must not contain 'Initial Catalog'. Use the databaseName parameter.\");\n}\n\nValidateSqlServerConnectionString(connectionString);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember SQL Server uses 'Initial Catalog' where MySQL/Postgres use 'Database'.","Remove Initial Catalog from any pasted connection string before saving.","Maintain per-backend config lint rules."],"tags":["sqlserver","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"}