in MySQL.Data/src/X/XDevAPI/BaseSession.cs [695:753]
private string ParseConnectionString(string connectionString)
{
var updatedConnectionString = string.Empty;
bool portProvided = false;
bool isDnsSrv = false;
var connectionOptionsDictionary = connectionString.Split(CONNECTION_DATA_KEY_SEPARATOR)
.Select(item => item.Split(new char[] { CONNECTION_DATA_VALUE_SEPARATOR }, 2))
.Where(item => item.Length == 2)
.ToDictionary(item => item[0], item => item[1]);
var serverOption = MySqlXConnectionStringBuilder.Options.Options.First(item => item.Keyword == SERVER_CONNECTION_OPTION_KEYWORD);
var connecttimeoutOption = MySqlXConnectionStringBuilder.Options.Options.First(item => item.Keyword == CONNECT_TIMEOUT_CONNECTION_OPTION_KEYWORD);
foreach (KeyValuePair<string, string> keyValuePair in connectionOptionsDictionary)
{
// Value is an equal or a semicolon
if (keyValuePair.Value == "=" || keyValuePair.Value == "\"")
throw new MySqlException(string.Format(Resources.InvalidConnectionStringValue, (keyValuePair.Value == "\"" ? ";" : "="), keyValuePair.Key));
// Key is not server or any of its synonyms.
if (keyValuePair.Key != serverOption.Keyword && !serverOption.Synonyms.Contains(keyValuePair.Key))
{
if ((connecttimeoutOption.Keyword == keyValuePair.Key || connecttimeoutOption.Synonyms.Contains(keyValuePair.Key)) &&
String.IsNullOrWhiteSpace(keyValuePair.Value))
throw new FormatException(ResourcesX.InvalidConnectionTimeoutValue);
if (keyValuePair.Key == PORT_CONNECTION_OPTION_KEYWORD)
portProvided = true;
if (keyValuePair.Key == DNS_SRV_CONNECTION_OPTION_KEYWORD)
isDnsSrv = Convert.ToBoolean(keyValuePair.Value);
updatedConnectionString += $"{keyValuePair.Key}{CONNECTION_DATA_VALUE_SEPARATOR}{keyValuePair.Value}{CONNECTION_DATA_KEY_SEPARATOR}";
continue;
}
// Key is server or one of its synonyms.
var updatedValue = keyValuePair.Value;
if (IsUnixSocket(keyValuePair.Value))
updatedValue = NormalizeUnixSocket(keyValuePair.Value);
// The value for the server connection option doesn't have a server list format.
if (FailoverManager.ParseHostList(updatedValue, true, false) == 1 && FailoverManager.FailoverGroup == null)
updatedConnectionString = $"{SERVER_CONNECTION_OPTION_KEYWORD}{CONNECTION_DATA_VALUE_SEPARATOR}{updatedValue}{CONNECTION_DATA_KEY_SEPARATOR}{updatedConnectionString}";
}
// DNS SRV Validation - Port cannot be provided by the user and multihost is not allowed if dns-srv is true
if (isDnsSrv)
{
if (portProvided)
throw new ArgumentException(Resources.DnsSrvInvalidConnOptionPort);
if (FailoverManager.FailoverGroup != null)
throw new ArgumentException(Resources.DnsSrvInvalidConnOptionMultihost);
}
// Default port must be added if not provided by the user.
if (FailoverManager.FailoverGroup == null)
return portProvided ? updatedConnectionString : $"{updatedConnectionString}{CONNECTION_DATA_KEY_SEPARATOR}{PORT_CONNECTION_OPTION_KEYWORD}{CONNECTION_DATA_VALUE_SEPARATOR}{X_PROTOCOL_DEFAULT_PORT}";
return $"{SERVER_CONNECTION_OPTION_KEYWORD}{CONNECTION_DATA_VALUE_SEPARATOR}{FailoverManager.FailoverGroup.ActiveHost.Host}{CONNECTION_DATA_KEY_SEPARATOR}" +
(!portProvided ? $"{PORT_CONNECTION_OPTION_KEYWORD}{CONNECTION_DATA_VALUE_SEPARATOR}{X_PROTOCOL_DEFAULT_PORT}{CONNECTION_DATA_KEY_SEPARATOR}" : string.Empty) +
updatedConnectionString;
}