Open roji opened 4 years ago
@roji Certainly not against this, but experience has shown that, at least for SQL Server
Therefore using the connection string as a key for the connection is inherently problematic without some form of normalization.
There are Many forms of what is essentially the same connection string. For example, there are multiple different key names that can be used for same option.
That is actually what I'd like to accomplish here. Npgsql already does connection normalization internally, as follows:
The problem is that the normalization step currently yields different strings because of the ordering issue, which is what I'd like to fix. Hope that makes sense, the relevant code is here.
DbConnectionStringBuilder internally uses a dictionary to keep key/value pairs, and the ConnectionString property iterates over the keys when building the string. Since Dictionary iteration order isn't stable, that means different strings can be returned for the same settings because keywords are ordered differently. This can lead to issues if resulting strings are used as keys to connection pools (or any other resource).
Simply applying a sort to ConnectionString's internal enumeration should fix this.
/cc @ajcvickers @bricelam