Skip to content

No way to hook up the Notice handler when using NpgsqlDataSource #5501

@LaXiS96

Description

@LaXiS96

The issue

using var pgsql = new NpgsqlDataSourceBuilder("Host=192.168.1.1;Username=postgres;Password=postgres;Database=postgres").Build();
using var cmd = pgsql.CreateCommand();
cmd.Connection.Notice += (sender, e) => Console.WriteLine(e.Notice);

throws:

Unhandled exception. System.NotSupportedException: Connection and transaction access is not supported on commands created from DbDataSource.
   at Npgsql.NpgsqlDataSourceCommand.get_DbConnection()
   at Npgsql.NpgsqlCommand.get_Connection()
   at Program.Main(String[] args) in Program.cs:line 3

There doesn't seem to be a way to configure this Notice handler anywhere else than on an NpgsqlConnection.
I would be fine with setting this handler on NpgsqlDataSource itself or through its builder, or even being able to define the notices' log level when logging with UseLoggerFactory (instead of them being at Debug level).

Further technical details

Npgsql version: 8.0.1
PostgreSQL version: 16.1
Operating system: Windows 10 19045.3803

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions