var builder1 = new MySqlConnectionStringBuilder { Server = "localhost", UserID = "root" };
var builder2 = new MySqlConnectionStringBuilder { UserID = "root", Server = "localhost" };
Console.WriteLine(builder1.ConnectionString);
Console.WriteLine(builder2.ConnectionString);
produces:
Server=localhost;User ID=root
User ID=root;Server=localhost
It's unexpected that the serialized connection string would depend on the order in which C# properties are set.
This may be an artifact of some logic in the base DbConnectionStringBuilder class, possibly in an attempt to preserve connection strings set via the string constructor? (Although normalization of property names and punctuation does occur; see example below.) Or it could be an unintentional side-effect of using a Dictionary to store the options, which tends to return Keys in the order in which they were inserted, although this is certainly not guaranteed by the implementation.
var builder3 = new MySqlConnectionStringBuilder("Server=localhost;User ID=root");
var builder4 = new MySqlConnectionStringBuilder("User ID=root;Server=localhost");
var builder5 = new MySqlConnectionStringBuilder("uid = \"root\" ; Server = localhost");
Console.WriteLine(builder3.ConnectionString);
Console.WriteLine(builder4.ConnectionString);
Console.WriteLine(builder5.ConnectionString);
produces:
Server=localhost;User ID=root
User ID=root;Server=localhost
User ID=root;Server=localhost
Since option key names and punctuation are already normalized by the implementation, it makes the most sense to also output the options themselves in a consistent order; OrdinalIgnoreCase would be simplest.
produces:
It's unexpected that the serialized connection string would depend on the order in which C# properties are set.
This may be an artifact of some logic in the base
DbConnectionStringBuilderclass, possibly in an attempt to preserve connection strings set via the string constructor? (Although normalization of property names and punctuation does occur; see example below.) Or it could be an unintentional side-effect of using aDictionaryto store the options, which tends to returnKeysin the order in which they were inserted, although this is certainly not guaranteed by the implementation.produces:
Since option key names and punctuation are already normalized by the implementation, it makes the most sense to also output the options themselves in a consistent order;
OrdinalIgnoreCasewould be simplest.