Пример #1
0
        private bool ConsoleCtrlCheck(CtrlTypes ctrlType)
        {
            if (trace != null)
            {
                Console.WriteLine("Stopping trace ...\n");
                trace.Stop();

                Console.WriteLine("Closing trace ...\n");
                trace.Close();
            }

            return(true);
        }
Пример #2
0
 public bool Disconnect()
 {
     Logger.Log("Trace:Disconnect(): Started", LogEntryType.Information);
     try
     {
         if (!_traceServer.IsClosed)
         {
             _traceServer.Close();
         }
         _traceServer.Dispose();
     }
     catch (Exception e)
     {
         OnDisconnectError(e);
         return(false);
     }
     Logger.Log("Trace:Disconnect(): Finished", LogEntryType.Information);
     return(true);
 }
Пример #3
0
        private static void ReadTrace(TraceServer trace, CancellationToken token)
        {
            while (trace.Read() && !token.IsCancellationRequested)
            {
                var eventClass = trace["EventClass"].ToString();
                if (string.Compare(eventClass, "RPC:Completed") == 0)
                {
                    var textData = trace["TextData"].ToString();
                    if (!textData.Contains("sp_reset_connection") &&
                        !textData.Contains("sp_trace") &&
                        !textData.Contains("sqlagent"))
                    {
                        eventQueue.Enqueue(textData);
                    }
                }
            }

            trace.Stop();
            trace.Close();
        }
Пример #4
0
        void DoWork(object SSAS)
        {
            string      SSASserver             = (string)SSAS;
            TraceTable  _SQLDestTableWriter    = null;
            TraceServer _SSASSourceTraceServer = null;
            int         _RetryCounter          = 0;
            bool        bFirstLoop             = true;

            while (bFirstLoop || _RetryCounter < Properties.Settings.Default.RestartRetries)
            {
                bFirstLoop = false;
                try
                {
                    //Grab connection to SSAS
                    bool bSuccess = ConnectOlap(out _SSASSourceTraceServer, SSASserver);

                    if (bSuccess)
                    {
                        //Grab connection to SQL and connect it with the SSAS trace
                        bSuccess = ConnectSQL(ref _SSASSourceTraceServer, out _SQLDestTableWriter, SSASserver);

                        if (bSuccess)
                        {
                            _RetryCounter = 0;

                            while (_SQLDestTableWriter.Write())
                            {
                                if (_SQLDestTableWriter.IsClosed)
                                {
                                    throw new Exception("SQL connection closed unexpectedly.");
                                }
                                if (_SSASSourceTraceServer.IsClosed)
                                {
                                    throw new Exception("SSAS connection closed unexpectedly.");
                                }
                            }
                        }
                    }
                }

                catch (Exception ex)
                {
                    StringBuilder messageText = new StringBuilder();

                    messageText.Append(DateTime.Now.ToString() + ":  Error reading trace: " + ex.Message).AppendLine();
                    messageText.Append(ex.StackTrace).AppendLine();

                    while (ex.InnerException != null)
                    {
                        messageText.Append("INNER EXCEPTION: ");
                        messageText.Append(ex.InnerException.Message).AppendLine();
                        messageText.Append(ex.InnerException.StackTrace).AppendLine();

                        ex = ex.InnerException;
                    }

                    WriteLog(messageText.ToString());
                    EventLog.WriteEntry(this.ServiceName, messageText.ToString(), EventLogEntryType.Warning);
                }

                try
                {
                    _SSASSourceTraceServer.Stop();
                    _SSASSourceTraceServer.Close();
                }
                catch { }
                try
                {
                    _SQLDestTableWriter.Close();
                }
                catch { }


                _RetryCounter++;

                if (_RetryCounter < Properties.Settings.Default.RestartRetries)
                {
                    StringBuilder messageText2 = new StringBuilder();
                    messageText2.Append(DateTime.Now.ToString() + ":  Exception caught tracing server: " + SSASserver + ", retry " + _RetryCounter + " of " + Properties.Settings.Default.RestartRetries
                                        + ". Pausing for " + Properties.Settings.Default.RestartDelayMinutes + " minute(s) then restarting automatically"
                                        ).AppendLine();
                    WriteLog(messageText2.ToString());
                    EventLog.WriteEntry(this.ServiceName, messageText2.ToString(), EventLogEntryType.Warning);
                    System.Threading.Thread.Sleep(new TimeSpan(0, Properties.Settings.Default.RestartDelayMinutes, 0));
                }
                else
                {
                    WriteLog(DateTime.Now.ToString() + ":  Exceeded the number of allowed retries for server: " + SSASserver);
                }
            }

            //if this one trace exceeded the number of retries so stop the service and stop all traces
            Stop();
        }