TechnitiumSoftware/DnsServer · error · Exception
The 'connectionString' parameter must not define 'Database'.
Error message
The 'connectionString' parameter must not define 'Database'. Configure the 'databaseName' parameter above instead.
What it means
QueryLogsPostgreSqlApp splits server connection info ('connectionString') from the target schema ('databaseName'). Internally it appends ' Database={databaseName};' to the user's string when creating the NpgsqlDataSource, so a pre-existing 'Database=' would collide. This error fires when the connectionString contains a 'Database=' segment (space-stripped, case-insensitive match).
Source
Thrown at Apps/QueryLogsPostgreSqlApp/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.Replace(" ", "").Contains("Database=", StringComparison.OrdinalIgnoreCase))
throw new Exception("The 'connectionString' parameter must not define 'Database'. Configure the 'databaseName' parameter above instead.");
if (!_connectionString.TrimEnd().EndsWith(';'))
_connectionString += ";";
_dataSource = NpgsqlDataSource.Create(_connectionString + $" Database={_databaseName};");
async Task ApplyConfig()
{
if (enableLogging)
{
await using (NpgsqlConnection connection = await _dataSource.OpenConnectionAsync())
{
await using (NpgsqlCommand command = connection.CreateCommand())
{
command.CommandText = @$"
CREATE TABLE IF NOT EXISTS dns_logs
(
dlid SERIAL PRIMARY KEY,View on GitHub (pinned to d0484b6c1e)
Solutions
- Delete the 'Database=...' pair from 'connectionString', leaving Host/Port/Username/Password/etc.
- Specify the target schema through the 'databaseName' parameter (default 'DnsQueryLogs').
- Confirm the trimmed string has no 'Database=' substring remaining.
Example fix
// before "connectionString": "Host=localhost;Database=DnsQueryLogs;Username=postgres;Password=pass;" // after "connectionString": "Host=localhost;Username=postgres;Password=pass;", "databaseName": "DnsQueryLogs"
Defensive patterns
Strategy: validation
Validate before calling
static void ValidatePostgresConnectionString(string cs)
{
if (cs.Replace(" ", "").Contains("Database=", StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException(
"connectionString must not contain 'Database='. The app appends it from databaseName.");
}
ValidatePostgresConnectionString(connectionString); Prevention
- Strip any 'Database=' segment before saving config.
- Document that NpgsqlDataSource receives ' Database={databaseName};' appended automatically.
- Lint config files for forbidden keywords per database backend.
When it happens
Trigger: ApplyConfig receives a 'connectionString' containing 'Database=...' (any casing, any spacing). The guard throws because the app injects the database itself via NpgsqlDataSource.Create(_connectionString + $" Database={_databaseName};").
Common situations: Reusing a PostgreSQL connection string from pgAdmin, DBeaver, or another .NET app that includes the database, and pasting it into dnsApp.config without trimming the Database 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 'Initial Ca
- Please specify a valid connection string in 'connectionStrin
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/6445645ec8bdb863.
Report an issue: GitHub.