private void Exit(string message)
 {
     _eventLog.WriteEntry(message, EventLogEntryType.Error);
     _thread = null;
     _instance = null;
     InvokeStopping(new SqlTraceService.StoppingEventArgs { Reason = message });
 }
        private void Term()
        {
            if (_termHandle != null) _termHandle.Set();
            if (_thread != null) _thread.Join();
            _thread = null;

            foreach (var database in GetDatabases())
            {
                try
                {
                    var conn = new SqlConnection(database.Value.InstanceConnectionString);
                    var server = new Server(new ServerConnection(conn));
                    var result = server.ConnectionContext.ExecuteNonQuery(string.Format(StopScript, _workDirectory));
                }
                catch
                {
                }
            }

            _instance = null;
        }
 public static void Start(EventLog eventLog, string workDirectory)
 {
     if (_instance == null) _instance = new SqlTraceManager(eventLog, workDirectory);
 }