/// <summary> /// Loads the properties from the connected server into a hashtable /// </summary> /// <param name="connection"></param> /// <returns></returns> private Dictionary <string, string> LoadServerProperties(MySqlConnection connection) { // load server properties Dictionary <string, string> hash = new Dictionary <string, string>(); MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection); try { using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { string key = reader.GetString(0); string value = reader.GetString(1); hash[key] = value; } } // Get time zone offset as numerical value timeZoneOffset = GetTimeZoneOffset(connection); return(hash); } catch (Exception ex) { MySqlTrace.LogError(ThreadID, ex.Message); throw; } }
/// <summary> /// Loads the properties from the connected server into a hashtable /// </summary> /// <param name="connection"></param> /// <returns></returns> private Hashtable LoadServerProperties(MySqlConnection connection) { // load server properties Hashtable hash = new Hashtable(); MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection); using (MySqlDataReader reader = cmd.ExecuteReader()) { try { while (reader.Read()) { string key = reader.GetString(0); string value = reader.GetString(1); hash[key] = value; } } catch (Exception ex) { MySqlTrace.LogError(ThreadID, ex.Message); throw; } } if (hash.Contains("max_allowed_packet")) { maxPacketSize = Convert.ToInt64(hash["max_allowed_packet"]); } return(hash); }
public void Close(bool isOpen) { try { if (isOpen) { try { packet.Clear(); packet.WriteByte((byte)DBCmd.QUIT); ExecutePacket(packet); } catch (Exception ex) { MySqlTrace.LogError(ThreadId, ex.ToString()); // Eat exception here. We should try to closing // the stream anyway. } } if (stream != null) { stream.Close(); } stream = null; } catch (Exception) { // we are just going to eat any exceptions // generated here } }
/// <summary> /// Loads the properties from the connected server into a hashtable /// </summary> /// <param name="connection"></param> /// <returns></returns> private Dictionary <string, string> LoadServerProperties(MySqlConnection connection) { // load server properties Dictionary <string, string> hash = new Dictionary <string, string>(); MySqlCommand cmd = new MySqlCommand(@"SELECT @@max_allowed_packet, @@character_set_client, @@character_set_connection, @@license, @@sql_mode, @@lower_case_table_names;", connection); try { using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { for (int i = 0; i <= reader.FieldCount - 1; i++) { string key = reader.GetName(i).Remove(0, 2); string value = reader[i].ToString(); hash[key] = value; } } } // Get time zone offset as numerical value timeZoneOffset = GetTimeZoneOffset(connection); return(hash); } catch (Exception ex) { MySqlTrace.LogError(ThreadID, ex.Message); throw; } }
private Dictionary <string, string> LoadServerProperties(MySqlConnection connection) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); MySqlCommand mySqlCommand = new MySqlCommand("SHOW VARIABLES", connection); Dictionary <string, string> result; try { using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader()) { while (mySqlDataReader.Read()) { string @string = mySqlDataReader.GetString(0); string string2 = mySqlDataReader.GetString(1); dictionary[@string] = string2; } } this.timeZoneOffset = this.GetTimeZoneOffset(connection); result = dictionary; } catch (Exception ex) { MySqlTrace.LogError(this.ThreadID, ex.Message); throw; } return(result); }
public SystemPerformanceMonitor(MySqlConnection connection) : base(connection) { string perfMonCategoryName = Resources.PerfMonCategoryName; if (connection.Settings.UsePerformanceMonitor && SystemPerformanceMonitor.procedureHardQueries == null) { try { SystemPerformanceMonitor.procedureHardQueries = new PerformanceCounter(perfMonCategoryName, "HardProcedureQueries", false); SystemPerformanceMonitor.procedureSoftQueries = new PerformanceCounter(perfMonCategoryName, "SoftProcedureQueries", false); } catch (Exception ex) { MySqlTrace.LogError(connection.ServerThread, ex.Message); } } }
private Driver TryToGetDriver() { int count = Interlocked.Decrement(ref available); if (count < 0) { Interlocked.Increment(ref available); return(null); } try { Driver driver = GetPooledConnection(); return(driver); } catch (Exception ex) { MySqlTrace.LogError(-1, ex.Message); Interlocked.Increment(ref available); throw; } }
public PerformanceMonitor(MySqlConnection connection) { this.connection = connection; var categoryName = Resources.PerfMonCategoryName; if (connection.Settings.UsePerformanceMonitor && procedureHardQueries == null) { try { procedureHardQueries = new PerformanceCounter(categoryName, "HardProcedureQueries", false); procedureSoftQueries = new PerformanceCounter(categoryName, "SoftProcedureQueries", false); } catch (Exception ex) { MySqlTrace.LogError(connection.ServerThread, ex.Message); } } }
private void LoadCharacterSets(MySqlConnection connection) { MySqlCommand mySqlCommand = new MySqlCommand("SHOW COLLATION", connection); try { using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader()) { this.charSets = new Dictionary <int, string>(); while (mySqlDataReader.Read()) { this.charSets[Convert.ToInt32(mySqlDataReader["id"], NumberFormatInfo.InvariantInfo)] = mySqlDataReader.GetString(mySqlDataReader.GetOrdinal("charset")); } } } catch (Exception ex) { MySqlTrace.LogError(this.ThreadID, ex.Message); throw; } }
private Driver TryToGetDriver() { if (Interlocked.Decrement(ref this.available) < 0) { Interlocked.Increment(ref this.available); return(null); } Driver pooledConnection; try { pooledConnection = this.GetPooledConnection(); } catch (Exception ex) { MySqlTrace.LogError(-1, ex.Message); Interlocked.Increment(ref this.available); throw; } return(pooledConnection); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } // Avoid cyclic calls to Dispose. disposed = true; try { ResetTimeout(1000); handler.Close(IsOpen); // if we are pooling, then release ourselves if (ConnectionString.Pooling) { MySqlPoolManager.RemoveConnection(this); } } catch (Exception ex) { if (disposing) { MySqlException mysqlEx = ex as MySqlException; if (mysqlEx == null) { MySqlTrace.LogError(0, ex.GetBaseException().Message); } else { MySqlTrace.LogError(mysqlEx.Number, ex.GetBaseException().Message); } } } finally { reader = null; IsOpen = false; } }
/// <summary> /// Loads all the current character set names and ids for this server /// into the charSets hashtable /// </summary> private void LoadCharacterSets(MySqlConnection connection) { MySqlCommand cmd = new MySqlCommand("SHOW COLLATION", connection); // now we load all the currently active collations try { using (MySqlDataReader reader = cmd.ExecuteReader()) { charSets = new Hashtable(); while (reader.Read()) { charSets[Convert.ToInt32(reader["id"], NumberFormatInfo.InvariantInfo)] = reader.GetString(reader.GetOrdinal("charset")); } } } catch (Exception ex) { MySqlTrace.LogError(ThreadID, ex.Message); throw; } }
protected virtual void Dispose(bool disposing) { if (this.disposed) { return; } this.disposed = true; try { this.ResetTimeout(1000); this.handler.Close(this.isOpen); if (this.connectionString.Pooling) { MySqlPoolManager.RemoveConnection(this); } } catch (Exception ex2) { if (disposing) { MySqlException ex = ex2 as MySqlException; if (ex == null) { MySqlTrace.LogError(0, ex2.GetBaseException().Message); } else { MySqlTrace.LogError(ex.Number, ex2.GetBaseException().Message); } } } finally { this.reader = null; this.isOpen = false; } }
public virtual void Configure(MySqlConnection connection) { bool firstConfigure = false; // if we have not already configured our server variables // then do so now if (serverProps == null) { firstConfigure = true; // load server properties serverProps = new Hashtable(); MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection); using (MySqlDataReader reader = cmd.ExecuteReader()) { try { while (reader.Read()) { string key = reader.GetString(0); string value = reader.GetString(1); serverProps[key] = value; } } catch (Exception ex) { MySqlTrace.LogError(ThreadID, ex.Message); throw; } } if (serverProps.Contains("max_allowed_packet")) { maxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]); } LoadCharacterSets(connection); } #if AUTHENTICATED string licenseType = serverProps["license"]; if (licenseType == null || licenseType.Length == 0 || licenseType != "commercial") { throw new MySqlException("This client library licensed only for use with commercially-licensed MySQL servers."); } #endif // 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 (charSet == null || charSet.Length == 0) { if (serverCharSetIndex >= 0) { charSet = (string)charSets[serverCharSetIndex]; } else { charSet = serverCharSet; } } // 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); object clientCharSet = serverProps["character_set_client"]; object connCharSet = serverProps["character_set_connection"]; if ((clientCharSet != null && clientCharSet.ToString() != charSet) || (connCharSet != null && connCharSet.ToString() != charSet)) { MySqlCommand setNamesCmd = new MySqlCommand("SET NAMES " + charSet, connection); setNamesCmd.ExecuteNonQuery(); } charSetCmd.ExecuteNonQuery(); if (charSet != null) { Encoding = CharSetMap.GetEncoding(Version, charSet); } else { Encoding = CharSetMap.GetEncoding(Version, "latin1"); } handler.Configure(); }