TechnitiumSoftware/DnsServer · error · Exception
The 'connectionString' parameter must not define 'Initial Ca
Error message
The 'connectionString' parameter must not define 'Initial Catalog'. Configure the 'databaseName' parameter above instead.
What it means
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.
Source
Thrown at Apps/QueryLogsSqlServerApp/App.cs:372
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 = @$"
IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = '{_databaseName}')
BEGIN
CREATE DATABASE ""{_databaseName}"";View on GitHub (pinned to d0484b6c1e)
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.
Example fix
// before "connectionString": "Server=localhost;Initial Catalog=DnsQueryLogs;User Id=sa;Password=pass;" // after "connectionString": "Server=localhost;User Id=sa;Password=pass;TrustServerCertificate=true;", "databaseName": "DnsQueryLogs"
Defensive patterns
Strategy: validation
Validate before calling
static void ValidateSqlServerConnectionString(string cs)
{
if (cs.Contains("Initial Catalog", StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException(
"connectionString must not contain 'Initial Catalog'. Use the databaseName parameter.");
}
ValidateSqlServerConnectionString(connectionString); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Please specify a valid connection string in 'connectionStrin
- 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/a1b5515c6f336e13.
Report an issue: GitHub.