-
Notifications
You must be signed in to change notification settings - Fork 874
No way to hook up the Notice handler when using NpgsqlDataSource #5501
Copy link
Copy link
Open
Milestone
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels