Skip to content

Conversation

DosenSuppe
Copy link
Member

@DosenSuppe DosenSuppe commented Aug 25, 2025

Problem:
Using a user other than postgres causes the connection test to fail.
This occurs because the ConnectionString lacks a Database attribute
during the test.
As a result, the npgsql defaults to using the User attribute as the
database name, which leads to a DatabaseNotFound error as no matching
database exists.

Solution:
Using a custom config for testing the database server's connection status
with database being "postgres".

INFO:
This migh lead to an edge-case where the user in unable to create/ delete
databases if the "postgres" database has been deleted.

Also added missing outline to the save button for the database config.

closes #539

@DosenSuppe DosenSuppe requested a review from a team August 25, 2025 07:14
@DosenSuppe DosenSuppe self-assigned this Aug 25, 2025
Copy link
Member

@1nf0rmagician 1nf0rmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While your changes are reasonable, they unfortunately do not tackle the actual issue.

Please reread the issue your are referencing and check the provided code reference as to were the improper/not-usage of the connection string for the database test occurs (which is in the .net code of the command center). The issue is specifically that the connection string is not used at all for the connection test but a default user instead. Disabling the save button will not help here, instead it would actually limit the users options to still modify the config even though we don't detect that the database is available.

Moreover, @MathoMathiasCamara whats your opinion on just disabling the save button while the connection test is running? I would have thought a small loading icon where we later show the connected/disconnected icons would be more user friendly, maybe with a hover text explaining that the connection to the db is currently tested.

Lastly, please rebase your changes after you have modified them onto the release/6 branch and start with #583 instead of this one. Our usual modus operandi is: Target lowest release first, then merge/port upwards 😊

1nf0rmagician
1nf0rmagician previously approved these changes Sep 23, 2025
Copy link
Member

@dbeuchler dbeuchler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested it with the latest versions again, and it seems to be fine. So there is no need for this whole change. Save should always be possible (after test) because on commissioning it is important to prepare the configs and later use the connection.

10-10-2025_13-23-02

The only improvements I have, were already mentioned by @1nf0rmagician: Show some kind of busy indicator and disable save button during test.

@1nf0rmagician
Copy link
Member

1nf0rmagician commented Oct 13, 2025

I have tested it with the latest versions again, and it seems to be fine.

I think this is a misunderstanding @dbeuchler, the issue that this change should solve is also visible on the gif you shared. While you have a correct database connection, assuming your user foo exists in the database server. The funny behaviour we observed was that, the test will show an error even if foo is a valid admin. This is because the connection used for the test has no database specified, for some reason it takes the user name as the database name for the test then. Obviously their won't be a foo database, hence the UI will show an error with the connection config.

@dbeuchler
Copy link
Member

I think this is a misunderstanding @dbeuchler, the issue that this change should solve is also visible on the gif you shared. While you have a correct database connection, assuming your user foo exists in the database server. The funny behaviour we observed was that, the test will show an error even if foo is a valid admin. This is because the connection used for the test has no database specified, for some reason it takes the user name as the database name for the test then. Obviously their won't be a foo database, hence the UI will show an error with the connection config.

I have investigated a bit more: You must always specify a database name when connecting to PostgreSQL. There is no supported way to connect without one. This is a PostgreSQL server limitation, not just an Npgsql behavior. It is also hidden in the implementation of Npgsql, if the database-name is empty, the username is used: https://github.com/npgsql/npgsql/blob/main/src/Npgsql/NpgsqlConnection.cs#L445

I also have checked ms-sql and there it is also not possible to connect without a database: For server-level checks, explicitly set Database=master in the connection string. The master database always exists and is suitable for administrative queries.

I don't like this "copy" of the DatabaseConfig<T> but I also have no better idea for dev - in future we could provide a separate method, e.g. CreateTestDatabaseConnectionString which creates a connection-string only for the connection test. And remove bool includeModel from CreateConnection-API - I will create an issue for that.

So thanks for the breakdown, I have learned again something 🤣

dbeuchler
dbeuchler previously approved these changes Oct 13, 2025
@dbeuchler dbeuchler added the bug Something isn't working label Oct 13, 2025
@dbeuchler dbeuchler added this to the Framework 8.x milestone Oct 13, 2025
@DosenSuppe DosenSuppe dismissed stale reviews from dbeuchler and 1nf0rmagician via a4410e2 October 14, 2025 12:43
Problem:
Using a user other than `postgres` causes the connection test to fail.
This occurs because the ConnectionString lacks a `Database` attribute
during the test.
As a result, the npgsql defaults to using the `User` attribute as the
database name, which leads to a `DatabaseNotFound` error as no matching
database exists.

Solution:
Using a custom config for testing the database server's connection status
with database being "postgres".

INFO:
This migh lead to an edge-case where the user in unable to create/ delete
databases if the "postgres" database has been deleted.

Also added missing `outline` to the save button for the database config.

closes #539
@DosenSuppe DosenSuppe force-pushed the fix/connectionstring-improperly-forwarded branch from a4410e2 to 3444287 Compare October 14, 2025 12:57
@1nf0rmagician 1nf0rmagician merged commit 16333c9 into dev Oct 16, 2025
8 checks passed
@1nf0rmagician 1nf0rmagician deleted the fix/connectionstring-improperly-forwarded branch October 16, 2025 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection string is not properly forwarded to connection Test

3 participants