@@ -35,11 +35,6 @@ public sealed class NpgsqlConnection : DbConnection, ICloneable, IComponent
3535 // Set this when disposed is called.
3636 bool _disposed ;
3737
38- // Set to true when the private NpgsqlDataSource is created by setting the ConnectionString property (legacy code path)
39- // in which case we want to retry if the DataSource has been disposed by the PoolManager as a reaction
40- // to Clean() or CleanAll()
41- bool _retryDisposedDataSource ;
42-
4338 /// <summary>
4439 /// The connection string, without the password after open (unless Persist Security Info=true)
4540 /// </summary>
@@ -227,6 +222,7 @@ void SetupDataSource()
227222 var dataSourceBuilder = new NpgsqlDataSourceBuilder ( canonical ) ;
228223 dataSourceBuilder . UseLoggerFactory ( NpgsqlLoggingConfiguration . GlobalLoggerFactory ) ;
229224 dataSourceBuilder . EnableParameterLogging ( NpgsqlLoggingConfiguration . GlobalIsParameterLoggingEnabled ) ;
225+ dataSourceBuilder . CreateLegacyDataSource ( ) ;
230226 var newDataSource = dataSourceBuilder . Build ( ) ;
231227
232228 _dataSource = PoolManager . GetOrAddPool ( canonical , newDataSource ) ;
@@ -369,11 +365,11 @@ async Task PerformMultiplexingStartupCheck(bool async, CancellationToken cancell
369365 }
370366 async Task < NpgsqlConnector > GetConnector ( NpgsqlTimeout timeout , bool async , CancellationToken cancellationToken )
371367 {
368+ Debug . Assert ( _dataSource != null ) ;
372369 while ( true )
373370 {
374371 try
375372 {
376- Debug . Assert ( _dataSource != null ) ;
377373 return await _dataSource . Get ( this , timeout , async, cancellationToken ) ;
378374 }
379375 // When using PoolManager (legacy code path setting NpgsqlConnection.ConnectionString), clearing a pool
@@ -384,7 +380,7 @@ async Task<NpgsqlConnector> GetConnector(NpgsqlTimeout timeout, bool async, Canc
384380 // _retryDisposedDataSource is false) we bubble up an eventual ObjectDisposedException as usual.
385381 catch ( ObjectDisposedException )
386382 {
387- if ( ! _retryDisposedDataSource )
383+ if ( ! _dataSource . IsLegacyDataSource )
388384 throw ;
389385 SetupDataSource ( ) ;
390386 }
@@ -411,7 +407,6 @@ public override string ConnectionString
411407 CheckClosed ( ) ;
412408
413409 _userFacingConnectionString = _connectionString = value ?? string . Empty ;
414- _retryDisposedDataSource = true ;
415410 SetupDataSource ( ) ;
416411 }
417412 }
@@ -1937,11 +1932,12 @@ public Task ReloadTypesAsync()
19371932
19381933 async Task BootstrapDataSource ( NpgsqlConnector connector , bool async )
19391934 {
1935+ Debug . Assert ( _dataSource != null ) ;
19401936 while ( true )
19411937 {
19421938 try
19431939 {
1944- await _dataSource ! . Bootstrap (
1940+ await _dataSource . Bootstrap (
19451941 connector ,
19461942 NpgsqlTimeout . Infinite ,
19471943 forceReload : true ,
@@ -1957,7 +1953,7 @@ async Task BootstrapDataSource(NpgsqlConnector connector, bool async)
19571953 // _retryDisposedDataSource is false) we bubble up an eventual ObjectDisposedException as usual.
19581954 catch ( ObjectDisposedException )
19591955 {
1960- if ( ! _retryDisposedDataSource )
1956+ if ( ! _dataSource . IsLegacyDataSource )
19611957 throw ;
19621958 SetupDataSource ( ) ;
19631959 }
0 commit comments