Skip to content

Allow setting connection string to null/empty - #4461

Merged
roji merged 2 commits into
npgsql:mainfrom
roji:NoConnectionString
May 16, 2022
Merged

roji merged 2 commits into
npgsql:mainfrom
roji:NoConnectionString

Conversation

@roji

@roji roji commented May 16, 2022

Copy link
Copy Markdown
Member

Fixes #4460

@roji
roji requested a review from vonzshik as a code owner May 16, 2022 10:50
@roji
roji enabled auto-merge (squash) May 16, 2022 10:50
@Brar

Brar commented May 16, 2022 •

Copy link
Copy Markdown
Member

In that context, out of curiosity, I just thought about what our behavior would be if there is no connection string but all the information needed to connect is set via environment variables.

It turns out that (at least from looking at our docs) this is not possible because you have to set at least the host as we don't default to unix domain sockets on Linux and localhost on Windows like libpq does and we don't support the PGHOST environment variable.

Is there a story behind that?

@roji

roji commented May 16, 2022

Copy link
Copy Markdown
Member Author

Good question, and it seems a bit tricky.

We could indeed allow connections even with an empty connection string, if all information is provided in environment variables. However, for perf reasons we'd probably want to assume the environment variables don't change during the application lifetime, otherwise we'd have to fetch them on every open (if anything is missing on the connection string, e.g. host, port, dbname...).

This is also valid for partial connection strings. For example, I never specify the port, because it defaults to 5432. But I imagine this can be overridden via PGPORT...

Can you please open a new issue for that? Since nobody asked for it we can probably leave it in the backlog for now, but good to track it...

Comment thread test/Npgsql.Tests/ConnectionTests.cs Resolved
@roji
roji requested a review from vonzshik May 16, 2022 15:27
@roji
roji merged commit 1f0d326 into npgsql:main May 16, 2022
@roji
roji deleted the NoConnectionString branch May 16, 2022 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot set null/empty connection string

3 participants