TechnitiumSoftware/DnsServer · error · Exception
Please specify a valid connection string in 'connectionStrin
Error message
Please specify a valid connection string in 'connectionString' parameter.
What it means
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.
Source
Thrown at Apps/QueryLogsSqlServerApp/App.cs:369
try
{
_dnsServer = dnsServer;
if (config is null)
throw new InvalidOperationException();
using JsonDocument jsonDocument = JsonDocument.Parse(config, _jsonParseOptions);
JsonElement jsonConfig = jsonDocument.RootElement;
bool enableLogging = jsonConfig.GetPropertyValue("enableLogging", false);
int maxQueueSize = jsonConfig.GetPropertyValue("maxQueueSize", 1000000);
_maxLogDays = jsonConfig.GetPropertyValue("maxLogDays", 0);
_maxLogRecords = jsonConfig.GetPropertyValue("maxLogRecords", 0);
_databaseName = jsonConfig.GetPropertyValue("databaseName", "DnsQueryLogs");
_connectionString = jsonConfig.GetPropertyValue("connectionString", null);
if (_connectionString is null)
throw new Exception("Please specify a valid connection string in 'connectionString' parameter.");
if (_connectionString.Contains("Initial Catalog", StringComparison.OrdinalIgnoreCase))
throw new Exception("The 'connectionString' parameter must not define 'Initial Catalog'. Configure the 'databaseName' parameter above instead.");
if (!_connectionString.TrimEnd().EndsWith(';'))
_connectionString += ";";
async Task ApplyConfig()
{
if (enableLogging)
{
await using (SqlConnection connection = new SqlConnection(_connectionString))
{
await connection.OpenAsync();
await using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = @$"View on GitHub (pinned to d0484b6c1e)
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.
Example fix
// before "connectionString": null // after "connectionString": "Server=localhost;User Id=sa;Password=pass;TrustServerCertificate=true;"
Defensive patterns
Strategy: validation
Validate before calling
static void EnsureSqlServerConnectionString(string? cs)
{
if (string.IsNullOrWhiteSpace(cs))
throw new InvalidOperationException(
"'connectionString' is missing. Set a SQL Server connection string.");
}
EnsureSqlServerConnectionString(connectionString); Prevention
- 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.
When it happens
Trigger: ApplyConfig is called with a JSON config lacking the 'connectionString' property or with it set to null. The null guard throws immediately.
Common situations: 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.
Related errors
- The 'connectionString' parameter must not define 'Initial Ca
- The 'connectionString' parameter must not define 'Database'.
- Please specify a valid connection string in 'connectionStrin
- The 'connectionString' parameter must not define 'Database'.
- Please specify a valid connection string in 'connectionStrin
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/9f4ed1bf4b879fd4.
Report an issue: GitHub.