{"record":{"id":"9f4ed1bf4b879fd4","repo":"TechnitiumSoftware/DnsServer","slug":"please-specify-a-valid-connection-string-in-conne-9f4ed1","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/QueryLogsSqlServerApp/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.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 = @$\"","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/QueryLogsSqlServerApp/App.cs#L351-L387","documentation":"QueryLogsSqlServerApp needs a SQL Server connection string to operate. The 'connectionString' property is read with a null default; this error fires when it is missing or null, before any SqlConnection is constructed. The app cannot persist DNS query logs without server coordinates.","triggerScenarios":"ApplyConfig is called with a JSON config lacking the 'connectionString' property or with it set to null. The null guard throws immediately.","commonSituations":"Newly added SqlServer query-log app whose config was never populated; a manual config edit that removed the line; or a templating/CI step that emitted an empty connectionString.","solutions":["Populate 'connectionString' in dnsApp.config with server/auth info, e.g. 'Server=localhost;User Id=sa;Password=pass;'.","Do NOT add 'Initial Catalog' (see error 44); use 'databaseName' for the schema.","Restart the DNS server/app so ApplyConfig reloads the corrected config."],"exampleFix":"// before\n\"connectionString\": null\n\n// after\n\"connectionString\": \"Server=localhost;User Id=sa;Password=pass;TrustServerCertificate=true;\"","handlingStrategy":"validation","validationCode":"static void EnsureSqlServerConnectionString(string? cs)\n{\n    if (string.IsNullOrWhiteSpace(cs))\n        throw new InvalidOperationException(\n            \"'connectionString' is missing. Set a SQL Server connection string.\");\n}\n\nEnsureSqlServerConnectionString(connectionString);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark connectionString required in config templates.","Validate config presence at startup with explicit messages.","Add a smoke-test that loads config and asserts required keys."],"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"}