Skip to content

Add NpgsqlDataSource constructor to ReplicationConnection#6527

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/integrate-replication-connection
Draft

Add NpgsqlDataSource constructor to ReplicationConnection#6527
Copilot wants to merge 3 commits intomainfrom
copilot/integrate-replication-connection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

ReplicationConnection directly constructs an NpgsqlConnection, bypassing NpgsqlDataSource entirely. This prevents using data source features like UsePeriodicPasswordProvider with replication connections.

Changes

  • ReplicationConnection: New private protected constructor accepting NpgsqlDataSource. Clones the data source's settings, overrides replication-specific values (Pooling=false, Enlist=false, KeepAlive=0, ReplicationMode), and creates an internal UnpooledDataSource that carries forward the original data source's configuration (password providers, logging, etc.). The internal data source is disposed with the connection. ConnectionString setter throws if constructed from a data source.
  • LogicalReplicationConnection / PhysicalReplicationConnection: Public constructors forwarding NpgsqlDataSource to base.
  • Tests: Open_with_data_source and ConnectionString_cannot_be_set_when_created_with_data_source in CommonReplicationTests.

Usage

var builder = new NpgsqlDataSourceBuilder(connectionString);
builder.UsePeriodicPasswordProvider(async (_, ct) => await GetPassword(ct), TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5));
await using var dataSource = builder.Build();

await using var conn = new LogicalReplicationConnection(dataSource);
await conn.Open();

Copilot AI assigned Copilot and roji Apr 4, 2026
Copilot AI linked an issue Apr 4, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 4, 2026 09:07
Add new constructors to LogicalReplicationConnection, PhysicalReplicationConnection,
and the base ReplicationConnection class that accept an NpgsqlDataSource parameter.
This allows using data source features like UsePeriodicPasswordProvider with
replication connections.

When created from a data source, an internal UnpooledDataSource is created with
the data source's configuration but with replication-specific settings (Pooling=false,
Enlist=false, KeepAlive=0, and the appropriate ReplicationMode).

The ConnectionString setter throws InvalidOperationException when the connection
was created with a data source, consistent with NpgsqlConnection behavior.

Fixes #4392

Agent-Logs-Url: https://github.com/npgsql/npgsql/sessions/2cf5ecb4-b7ee-446f-9ff1-b083c127e961

Co-authored-by: roji <1862641+roji@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate ReplicationConnection with NpgsqlDataSource Add NpgsqlDataSource constructor to ReplicationConnection Apr 4, 2026
Copilot finished work on behalf of roji April 4, 2026 09:11
Copilot AI requested a review from roji April 4, 2026 09:11
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.

Integrate ReplicationConnection with NpgsqlDataSource

2 participants