/// <summary> /// Loads the properties from the connected server into a hashtable /// </summary> /// <param name="connection"></param> /// <returns></returns> private Dictionary <string, string> LoadServerProperties(MyCatConnection connection) { // load server properties Dictionary <string, string> hash = new Dictionary <string, string>(); MyCatCommand cmd = new MyCatCommand("SHOW VARIABLES", connection); try { using (MyCatDataReader 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 = TimeZoneInfo.Local.BaseUtcOffset.Hours; return(hash); } catch (Exception ex) { MyCatTrace.LogError(ThreadID, ex.Message); throw; } }
public override void CloseQuery(MyCatConnection connection, int statementId) { base.CloseQuery(connection, statementId); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.QueryClosed, Resources.TraceQueryDone, driverId); }
public ProcedureCacheEntry GetProcedure(MyCatConnection conn, string spName, string cacheKey) { ProcedureCacheEntry proc = null; if (cacheKey != null) { int hash = cacheKey.GetHashCode(); lock (procHash) { procHash.TryGetValue(hash, out proc); } } if (proc == null) { proc = AddNew(conn, spName); conn.PerfMonitor.AddHardProcedureQuery(); if (conn.Settings.Logging) { MyCatTrace.LogInformation(conn.ServerThread, String.Format(Resources.HardProcQuery, spName)); } } else { conn.PerfMonitor.AddSoftProcedureQuery(); if (conn.Settings.Logging) { MyCatTrace.LogInformation(conn.ServerThread, String.Format(Resources.SoftProcQuery, spName)); } } return(proc); }
public override int PrepareStatement(string sql, ref MyCatField[] parameters) { int statementId = base.PrepareStatement(sql, ref parameters); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.StatementPrepared, Resources.TraceStatementPrepared, driverId, sql, statementId); return(statementId); }
internal void HandleTimeoutOrThreadAbort(Exception ex) { bool isFatal = false; if (isKillQueryConnection) { // Special connection started to cancel a query. // Abort will prevent recursive connection spawning Abort(); if (ex is TimeoutException) { Throw(new MyCatException(Resources.Timeout, true, ex)); } else { return; } } try { // Do a fast cancel.The reason behind small values for connection // and command timeout is that we do not want user to wait longer // after command has already expired. // Microsoft's SqlClient seems to be using 5 seconds timeouts // here as well. // Read the error packet with "interrupted" message. CancelQuery(5); driver.ResetTimeout(5000); if (Reader != null) { #if NETSTANDARD1_3 foreach (var x in Reader) { x.Dispose(); } #else foreach (var x in Reader) { x.Close(); } #endif Reader = null; } } catch (Exception ex2) { MyCatTrace.LogWarning(ServerThread, "Could not kill query, " + " aborting connection. Exception was " + ex2.Message); Abort(); isFatal = true; } if (ex is TimeoutException) { Throw(new MyCatException(Resources.Timeout, isFatal, ex)); } }
public override List <MyCatError> ReportWarnings(MyCatConnection connection) { List <MyCatError> warnings = base.ReportWarnings(connection); foreach (MyCatError warning in warnings) { MyCatTrace.TraceEvent(TraceEventType.Warning, MyCatTraceEventType.Warning, Resources.TraceWarning, driverId, warning.Level, warning.Code, warning.Message); } return(warnings); }
public override void ExecuteStatement(MyCatPacket packetToExecute) { base.ExecuteStatement(packetToExecute); int pos = packetToExecute.Position; packetToExecute.Position = 1; int statementId = packetToExecute.ReadInteger(4); packetToExecute.Position = pos; MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.StatementExecuted, Resources.TraceStatementExecuted, driverId, statementId, ThreadID); }
internal void Abort() { try { driver.Close(); } catch (Exception ex) { MyCatTrace.LogWarning(ServerThread, String.Concat("Error occurred aborting the connection. Exception was: ", ex.Message)); } finally { this.isInUse = false; } SetState(ConnectionState.Closed, true); }
protected override long GetResult(int statementId, ref long affectedRows, ref long insertedId) { try { var fieldCount = base.GetResult(statementId, ref affectedRows, ref insertedId); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.ResultOpened, Resources.TraceResult, driverId, fieldCount, affectedRows, insertedId); return(fieldCount); } catch (MyCatException ex) { // we got an error so we report it MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.Error, Resources.TraceOpenResultError, driverId, ex.Number, ex.Message); throw ex; } }
public override bool FetchDataRow(int statementId, int columns) { try { bool b = base.FetchDataRow(statementId, columns); if (b) { rowSizeInBytes += (handler as NativeDriver).Packet.Length; } return(b); } catch (MyCatException ex) { MyCatTrace.TraceEvent(TraceEventType.Error, MyCatTraceEventType.Error, Resources.TraceFetchError, driverId, ex.Number, ex.Message); throw ex; } }
public SystemPerformanceMonitor(MyCatConnection connection) : base(connection) { string 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) { MyCatTrace.LogError(connection.ServerThread, ex.Message); } } }
public override ResultSet NextResult(int statementId, bool force) { // first let's see if we already have a resultset on this statementId if (activeResult != null) { //oldRS = activeResults[statementId]; if (Settings.UseUsageAdvisor) { ReportUsageAdvisorWarnings(statementId, activeResult); } MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.ResultClosed, Resources.TraceResultClosed, driverId, activeResult.TotalRows, activeResult.SkippedRows, rowSizeInBytes); rowSizeInBytes = 0; activeResult = null; } activeResult = base.NextResult(statementId, force); return(activeResult); }
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) { MyCatTrace.LogError(-1, ex.Message); Interlocked.Increment(ref available); throw; } }
/// <summary> /// Loads all the current character set names and ids for this server /// into the charSets hashtable /// </summary> private void LoadCharacterSets(MyCatConnection connection) { MyCatCommand cmd = new MyCatCommand("SHOW COLLATION", connection); // now we load all the currently active collations try { using (MyCatDataReader reader = cmd.ExecuteReader()) { charSets = new Dictionary <int, string>(); while (reader.Read()) { charSets[Convert.ToInt32(reader["id"], NumberFormatInfo.InvariantInfo)] = reader.GetString(reader.GetOrdinal("charset")); } } } catch (Exception ex) { MyCatTrace.LogError(ThreadID, ex.Message); throw; } }
public override void SendQuery(MyCatPacket p) { rowSizeInBytes = 0; string cmdText = Encoding.GetString(p.Buffer, 5, p.Length - 5); string normalized_query = null; if (cmdText.Length > 300) { QueryNormalizer normalizer = new QueryNormalizer(); normalized_query = normalizer.Normalize(cmdText); cmdText = cmdText.Substring(0, 300); } base.SendQuery(p); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.QueryOpened, Resources.TraceQueryOpened, driverId, ThreadID, cmdText); if (normalized_query != null) { MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.QueryNormalized, Resources.TraceQueryNormalized, driverId, ThreadID, normalized_query); } }
public override void SetDatabase(string dbName) { base.SetDatabase(dbName); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.NonQuery, Resources.TraceSetDatabase, driverId, dbName); }
private void ReportUsageAdvisorWarnings(int statementId, ResultSet rs) { #if !RT if (!Settings.UseUsageAdvisor) { return; } if (HasStatus(ServerStatusFlags.NoIndex)) { MyCatTrace.TraceEvent(TraceEventType.Warning, MyCatTraceEventType.UsageAdvisorWarning, Resources.TraceUAWarningNoIndex, driverId, UsageAdvisorWarningFlags.NoIndex); } else if (HasStatus(ServerStatusFlags.BadIndex)) { MyCatTrace.TraceEvent(TraceEventType.Warning, MyCatTraceEventType.UsageAdvisorWarning, Resources.TraceUAWarningBadIndex, driverId, UsageAdvisorWarningFlags.BadIndex); } // report abandoned rows if (rs.SkippedRows > 0) { MyCatTrace.TraceEvent(TraceEventType.Warning, MyCatTraceEventType.UsageAdvisorWarning, Resources.TraceUAWarningSkippedRows, driverId, UsageAdvisorWarningFlags.SkippedRows, rs.SkippedRows); } // report not all fields accessed if (!AllFieldsAccessed(rs)) { StringBuilder notAccessed = new StringBuilder(""); string delimiter = ""; for (int i = 0; i < rs.Size; i++) { if (!rs.FieldRead(i)) { notAccessed.AppendFormat("{0}{1}", delimiter, rs.Fields[i].ColumnName); delimiter = ","; } } MyCatTrace.TraceEvent(TraceEventType.Warning, MyCatTraceEventType.UsageAdvisorWarning, Resources.TraceUAWarningSkippedColumns, driverId, UsageAdvisorWarningFlags.SkippedColumns, notAccessed.ToString()); } // report type conversions if any if (rs.Fields != null) { foreach (MyCatField f in rs.Fields) { StringBuilder s = new StringBuilder(); string delimiter = ""; foreach (Type t in f.TypeConversions) { s.AppendFormat("{0}{1}", delimiter, t.Name); delimiter = ","; } if (s.Length > 0) { MyCatTrace.TraceEvent(TraceEventType.Warning, MyCatTraceEventType.UsageAdvisorWarning, Resources.TraceUAWarningFieldConversion, driverId, UsageAdvisorWarningFlags.FieldConversion, f.ColumnName, s.ToString()); } } } #endif }
public override void Open() { base.Open(); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.ConnectionOpened, Resources.TraceOpenConnection, driverId, Settings.ConnectionString, ThreadID); }
public override void Close() { base.Close(); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.ConnectionClosed, Resources.TraceCloseConnection, driverId); }
public override void CloseStatement(int id) { base.CloseStatement(id); MyCatTrace.TraceEvent(TraceEventType.Information, MyCatTraceEventType.StatementClosed, Resources.TraceStatementClosed, driverId, id); }