public ConnectionInfo GetConnectionInfo() { // Other than the hosts, these are MOST of the other possibilities. // Not since they all contain and "=" I am filtering by that. //var options = new[] //{ // "abortConnect=","allowAdmin=","channelPrefix=","connectRetry=","connectTimeout=", // "configChannel=","defaultDatabase=","keepAlive=","name=","password="******"proxy=","resolveDns=","serviceName=","ssl=","sslHost=", // "syncTimeout=","tiebreaker=","version=","writeBuffer=" //}; // Example connection string: localhost,resolvedns=1 // Example connection string: localhost,abortConnect=true // Example connection string: localhost,password=awesomesuace, name=stuffandthings var sections = _connectionString.Split(StringSeparators.Comma); foreach (var section in sections) { if (section.Contains('=')) { continue; } // We can only capture the first server we detect. It could be that there are many.... var hostPortPair = section.Split(StringSeparators.Colon); var port = hostPortPair.Length == 2 ? hostPortPair[1] : null; return(new ConnectionInfo(ConnectionStringParserHelper.NormalizeHostname(hostPortPair[0]), port, null)); } return(new ConnectionInfo(null, null, null)); }
public ConnectionInfo GetConnectionInfo() { var host = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value; var hasMultipleHosts = host != null && host.IndexOf(',') != -1; if (hasMultipleHosts) { host = null; } else if (host != null) { host = ConnectionStringParserHelper.NormalizeHostname(host); } var portPathOrId = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _portKeys)?.Value; if (portPathOrId == null && host != null) { portPathOrId = "default"; } var databaseName = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _databaseNameKeys)?.Value; return(new ConnectionInfo(host, portPathOrId, databaseName)); }
public ConnectionInfo GetConnectionInfo() { var host = ParseHost(); if (host != null) { host = ConnectionStringParserHelper.NormalizeHostname(host); } var portPathOrId = ParsePortPathOrId(); var databaseName = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _databaseNameKeys)?.Value; return(new ConnectionInfo(host, portPathOrId, databaseName)); }