in MySQL.Data/src/Driver.cs [212:289]
public virtual async Task ConfigureAsync(MySqlConnection connection, bool execAsync, CancellationToken cancellationToken)
{
bool firstConfigure = false;
// if we have not already configured our server variables
// then do so now
if (serverProps == null)
{
firstConfigure = true;
// if we are in a pool and the user has said it's ok to cache the
// properties, then grab it from the pool
try
{
if (Pool != null && Settings.CacheServerProperties)
{
if (Pool.ServerProperties == null)
Pool.ServerProperties = await LoadServerPropertiesAsync(connection, execAsync, cancellationToken).ConfigureAwait(false);
serverProps = Pool.ServerProperties;
}
else
serverProps = await LoadServerPropertiesAsync(connection, execAsync, cancellationToken).ConfigureAwait(false);
await LoadCharacterSetsAsync(connection, execAsync, cancellationToken).ConfigureAwait(false);
}
catch (MySqlException ex)
{
// expired password capability
if (ex.Number == 1820)
{
IsPasswordExpired = true;
return;
}
throw;
}
}
// if the user has indicated that we are not to reset
// the connection and this is not our first time through,
// then we are done.
if (!Settings.ConnectionReset && !firstConfigure) return;
string charSet = ConnectionString.CharacterSet;
if (string.IsNullOrEmpty(charSet))
{
if (ConnectionCharSetIndex >= 0 && CharacterSets.ContainsKey(ConnectionCharSetIndex))
charSet = CharacterSets[ConnectionCharSetIndex];
else
charSet = serverCharSet;
}
if (serverProps.ContainsKey("max_allowed_packet"))
MaxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]);
// now tell the server which character set we will send queries in and which charset we
// want results in
MySqlCommand charSetCmd = new MySqlCommand("SET character_set_results=NULL",
connection)
{ InternallyCreated = true };
string clientCharSet;
serverProps.TryGetValue("character_set_client", out clientCharSet);
string connCharSet;
serverProps.TryGetValue("character_set_connection", out connCharSet);
if ((clientCharSet != null && clientCharSet.ToString() != charSet) ||
(connCharSet != null && connCharSet.ToString() != charSet))
{
using MySqlCommand setNamesCmd = new MySqlCommand("SET NAMES " + charSet, connection);
setNamesCmd.InternallyCreated = true;
await setNamesCmd.ExecuteNonQueryAsync(execAsync, cancellationToken).ConfigureAwait(false);
}
// sets character_set_results to null to return values in their original character set
await charSetCmd.ExecuteNonQueryAsync(execAsync, cancellationToken).ConfigureAwait(false);
Encoding = CharSetMap.GetEncoding(charSet ?? "utf-8");
handler.Configure();
}