@@ -417,25 +417,35 @@ public Boolean Connect(bool displayErrorPopup = false)
417417 break ;
418418
419419 case eDBTypes . PostgreSQL :
420- string postgreSQLHost = TNSCalculated ;
421- int ? port = null ;
422- if ( TNSCalculated . Contains ( ':' , StringComparison . Ordinal ) )
420+ var pg = new NpgsqlConnectionStringBuilder ( ) ;
421+ if ( string . IsNullOrEmpty ( ConnectionStringCalculated ) )
423422 {
424- var parts = TNSCalculated . Split ( ':' , 2 ) ;
425- postgreSQLHost = parts [ 0 ] ;
426- if ( int . TryParse ( parts [ 1 ] , out int p ) ) port = p ;
427- }
428- ValidateHostPort ( postgreSQLHost , port ) ;
423+ string postgreSQLHost = TNSCalculated ;
424+ int ? port = null ;
425+ if ( TNSCalculated . Contains ( ':' , StringComparison . Ordinal ) )
426+ {
427+ var parts = TNSCalculated . Split ( ':' , 2 ) ;
428+ postgreSQLHost = parts [ 0 ] ;
429+ if ( int . TryParse ( parts [ 1 ] , out int p ) ) port = p ;
430+ }
431+ ValidateHostPort ( postgreSQLHost , port ) ;
429432
430- var pg = new NpgsqlConnectionStringBuilder
433+ pg = new NpgsqlConnectionStringBuilder
434+ {
435+ Host = postgreSQLHost ,
436+ Database = Database . Name ?? string . Empty ,
437+ Username = UserCalculated ,
438+ Password = EncryptionHandler . DecryptwithKey ( PassCalculated )
439+ } ;
440+ if ( port . HasValue ) pg . Port = port . Value ;
441+ }
442+ else
431443 {
432- Host = postgreSQLHost ,
433- Database = Database . Name ?? string . Empty ,
434- Username = UserCalculated ,
435- Password = EncryptionHandler . DecryptwithKey ( PassCalculated )
436- } ;
437- if ( port . HasValue ) pg . Port = port . Value ;
438- Database . ConnectionString = pg . ConnectionString ;
444+ pg = new NpgsqlConnectionStringBuilder
445+ {
446+ ConnectionString = GetConnectionString ( )
447+ } ;
448+ }
439449
440450 oConn = new NpgsqlConnection ( pg . ConnectionString ) ;
441451 oConn . Open ( ) ;
@@ -1045,4 +1055,4 @@ public string GetRecordCount(string SQL)
10451055 }
10461056
10471057 }
1048- }
1058+ }
0 commit comments