Exemplo n.º 1
0
        private void GetConfigValueBoolean(ref int Value, string ConfigEntry)
        {
            string ls_value;

            SqlConnection con     = InternalMethods.GetNewConnection(dbConInfo[0], dbConInfo[1]);
            SqlCommand    cmd     = new SqlCommand("SELECT dbo.fn_get_global_preference('SERVERCONFIG', '" + ConfigEntry + "') FROM c_1_Record", con);
            object        dbValue = cmd.ExecuteScalar();

            con.Close();
            if (null == dbValue || dbValue.ToString().Length < 1)
            {
                return;
            }

            ls_value = dbValue.ToString().Substring(0, 1).ToUpper();
            if (ls_value.Length > 0)
            {
                if (ls_value == "Y" || ls_value == "T")
                {
                    Value = 1;
                }
                else
                {
                    Value = 0;
                }
            }
        }
Exemplo n.º 2
0
 private void mainLoop()
 {
     while (!shutdown)
     {
         SqlConnection con = null;
         try
         {
             con = InternalMethods.GetNewConnection(dbConInfo[0], dbConInfo[1]);
             con.Close();
             if (!running)
             {
                 EPSEventLog.WriteEntry("Connection to " + dbConInfo[0] + "." + dbConInfo[1] + " is available.  Starting service threads...", EventLogEntryType.Information);
                 startServices();
             }
         }
         catch (Exception exc)
         {
             if (running)
             {
                 EPSEventLog.WriteEntry("Connection to " + dbConInfo[0] + "." + dbConInfo[1] + " is not available.  Stopping service threads..." + Environment.NewLine + Environment.NewLine + exc.ToString(), EventLogEntryType.Warning);
                 stopServices();
             }
         }
         finally
         {
             try
             {
                 con.Dispose();
             }
             catch {}
         }
         Thread.Sleep(5000);
         GC.Collect();
     }
 }
        public void RemoveLock(int ComputerID, long ServiceID, string SystemUserID)
        {
            SqlConnection con = InternalMethods.GetNewConnection(Server, Database);
            SqlCommand    cmd = new SqlCommand("DELETE FROM o_User_Service_Lock " +
                                               "WHERE patient_workplan_item_id = " + ServiceID + " " +
                                               "AND user_id = '" + SystemUserID + "' AND computer_id = " +
                                               ComputerID.ToString(), con);

            cmd.ExecuteNonQuery();
        }
        public bool IsLocked(int ComputerID, long ServiceID, string SystemUserID)
        {
            SqlConnection con = InternalMethods.GetNewConnection(Server, Database);
            SqlCommand    cmd = new SqlCommand("SELECT COUNT(*) FROM " +
                                               "o_User_Service_Lock WHERE patient_workplan_item_id = '" +
                                               ServiceID + "' AND user_id = '" + SystemUserID + "' AND " +
                                               "computer_id = " + ComputerID.ToString(), con);
            int lockCount = (int)cmd.ExecuteScalar();

            return(lockCount > 0);
        }
Exemplo n.º 5
0
        static internal string DecryptString(string value)
        {
            try
            {
                byte[] resultBA = new byte[value.Length / 2], valueBA = new byte[value.Length / 2];
                byte[] iv       = new byte[] { 0x14, 0xD7, 0x5B, 0xA2, 0x47, 0x83, 0x0F, 0xC4 };
                System.Text.ASCIIEncoding ascEncoding = new System.Text.ASCIIEncoding();
                byte[] key = new byte[24] {
                    0x21, 0x24, 0x25, 0x23, 0x34, 0x32, 0x37, 0x34, 0x38, 0x6A, 0x73, 0x54, 0x54, 0x4C, 0x7A, 0X51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };

                MemoryStream memStream = new MemoryStream();
                byte[]       tempBA    = InternalMethods.HexStringToBytes(value);
                memStream.Write(tempBA, 0, tempBA.Length);
                memStream.Position = 0;

                System.Security.Cryptography.TripleDES
                    cryptoServiceProvider = System.Security.Cryptography.TripleDESCryptoServiceProvider.Create();

                System.Security.Cryptography.ICryptoTransform
                    decryptor = cryptoServiceProvider.CreateDecryptor(key, iv);

                System.Security.Cryptography.CryptoStream
                    cStream = new System.Security.Cryptography.CryptoStream(
                    memStream,
                    decryptor,
                    System.Security.Cryptography.CryptoStreamMode.Read);

                cStream.Read(resultBA, 0, resultBA.Length);
                cStream.Close();

                // Find the first zero
                int i = 0;
                for (; i < resultBA.GetLength(0); i++)
                {
                    if (resultBA[i] == 0)
                    {
                        break;
                    }
                }
                return(ascEncoding.GetString(resultBA, 0, i));
            }
            catch (Exception exc)
            {
                EPSEventLog.WriteEntry("Decryption failure.  Returning original value" + Environment.NewLine + exc.Source, EventLogEntryType.Error);
                return(value);
            }
        }
        public void ServiceError(long WorkplanItemID, string SystemUserID)
        {
            SqlConnection con = InternalMethods.GetNewConnection(Server, Database);
            SqlCommand    cmd = new SqlCommand("EXEC jmj_set_service_error " +
                                               WorkplanItemID.ToString() + ", '" + SystemUserID + "','" + SystemUserID + "','N'", con);

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception exc)
            {
                EPSEventLog.WriteEntry("Error in ServiceError()" + Environment.NewLine +
                                       exc.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }
Exemplo n.º 7
0
        private string[] GetSystemUserID(int ComputerID)
        {
            System.Collections.ArrayList userIDList = new ArrayList();
            SqlConnection con = InternalMethods.GetNewConnection(dbConInfo[0], dbConInfo[1]);
            SqlCommand    cmd = new SqlCommand("SELECT DISTINCT system_user_id " +
                                               "FROM o_Server_Component WHERE computer_id=" + ComputerID +
                                               " AND component_id = 'JMJ_SERVERSERVICE' AND status='OK'", con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                userIDList.Add(reader["system_user_id"].ToString());
            }
            reader.Close();
            con.Close();
            return((string[])userIDList.ToArray(Type.GetType("System.String")));
        }
Exemplo n.º 8
0
        private int GetComputerID()
        {
            SqlConnection con = InternalMethods.GetNewConnection(dbConInfo[0], dbConInfo[1]);
            SqlCommand    cmd = new SqlCommand("SELECT TOP 1 computer_id " +
                                               "FROM o_Computers WHERE computername='" +
                                               Environment.MachineName + "' AND logon_id='" +
                                               Environment.UserName + "' AND status='OK'", con);
            // Get computer_id
            object computerID = cmd.ExecuteScalar();

            if (null == computerID)
            {
                // Create record and return computer_id
                try
                {
                    cmd.CommandText = "INSERT o_Computers (computername, logon_id, status) " +
                                      "VALUES('" + Environment.MachineName + "','" + Environment.UserName + "','OK')";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "SELECT TOP 1 computer_id " +
                                      "FROM o_Computers WHERE computername='" +
                                      Environment.MachineName + "' AND logon_id='" +
                                      Environment.UserName + "' AND status='OK'";
                    computerID = cmd.ExecuteScalar();
                    if (null == computerID)
                    {
                        goto ERROR;
                    }
                }
                catch
                {
                    goto ERROR;
                }
            }
            con.Close();
            return(Int32.Parse(computerID.ToString()));

ERROR:
            try
            {
                con.Close();
            }
            catch {}
            throw new Exception("Error creating o_Computers record for " + Environment.MachineName + "\\" + Environment.UserName);
        }
Exemplo n.º 9
0
        private void GetConfigValue(ref string Value, string ConfigEntry)
        {
            string ls_value;

            SqlConnection con     = InternalMethods.GetNewConnection(dbConInfo[0], dbConInfo[1]);
            SqlCommand    cmd     = new SqlCommand("SELECT dbo.fn_get_global_preference('SERVERCONFIG', '" + ConfigEntry + "') FROM c_1_Record", con);
            object        dbValue = cmd.ExecuteScalar();

            con.Close();
            if (null == dbValue)
            {
                return;
            }
            ls_value = dbValue.ToString();
            if (ls_value.Length > 0)
            {
                Value = ls_value;
            }
        }
Exemplo n.º 10
0
        private int[] GetServiceID(int ComputerID)
        {
            System.Collections.ArrayList serviceIDList = new ArrayList();
            SqlConnection con = InternalMethods.GetNewConnection(dbConInfo[0], dbConInfo[1]);
            SqlCommand    cmd = new SqlCommand("SELECT service_id " +
                                               "FROM o_Server_Component WHERE computer_id=" + ComputerID +
                                               " AND component_id <> 'JMJ_SERVERSERVICE' AND status='OK'", con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                serviceIDList.Add(reader["service_id"].ToString());
            }
            reader.Close();
            con.Close();
            object[] res  = serviceIDList.ToArray();
            int[]    iRes = new int[res.Length];
            for (int i = 0; i < iRes.Length; i++)
            {
                iRes[i] = Int32.Parse(res[i].ToString());
            }
            return(iRes);
        }
/* moved to InternalMethods
 *              public static SqlConnection GetNewConnection(string Server, string Database)
 *              {
 *                      SqlConnection con = new SqlConnection("Server="+Server+";Database="+Database+";Integrated Security=SSPI;POOLING=FALSE");
 *                      con.Open();
 *                      try
 *                      {
 *                              string ls_pref;
 *                              string ls_approlecred;
 *                              string ls_sql;
 *
 *                              SqlCommand cmd = new SqlCommand("SELECT dbo.fn_get_global_preference('SYSTEM', 'system_bitmap') FROM c_1_Record",con);
 *                              object dbValue = cmd.ExecuteScalar();
 *                              if(null==dbValue)
 *                              {
 *                                      ls_approlecred = "applesauce28";
 *                              }
 *                              else
 *                              {
 *                                      ls_pref = dbValue.ToString();
 *                                      ls_approlecred = InternalMethods.DecryptString(ls_pref);
 *                              }
 *
 *                              ls_sql = "sp_setapprole 'cprsystem', '" + ls_approlecred + "'";
 *                              SqlCommand com = new SqlCommand(ls_sql, con);
 *                              com.ExecuteNonQuery();
 *                      }
 *                      catch(Exception exc)
 *                      {
 *                              EPSEventLog.WriteEntry("Error executing sp_setapprole:"+Environment.NewLine+exc.ToString(),EventLogEntryType.Error);
 *                      }
 *                      return con;
 *              }
 */
        private void MainServiceLoop()
        {
#if (DEBUG)
            string path = @"C:\Program Files\JMJ\EncounterPRO Server";
#else
            string path = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
#endif
            EventLog      log    = new EventLog("Application", Environment.MachineName, "EncounterPROService");
            SqlConnection sqlCon = null;

CONNECT:
            try
            {
                sqlCon = InternalMethods.GetNewConnection(Server, Database);
            }
            catch
            {
                return;
            }

            SqlCommand    cmd = null;
            SqlDataReader rdr = null;

            // Remove locks before starting
            try
            {
                cmd = new SqlCommand("DELETE o_user_service_lock WHERE computer_id = " + ComputerID.ToString(), sqlCon);
                cmd.ExecuteNonQuery();

                cmd = new SqlCommand("DELETE o_users WHERE computer_id = " + ComputerID.ToString(), sqlCon);
                cmd.ExecuteNonQuery();
            }
            catch (Exception exc)
            {
                log.WriteEntry("Failed to clean up locks and users" + Environment.NewLine + exc.ToString(), EventLogEntryType.Warning);
            }


            DateTime LastRuntime = DateTime.Now;
            try
            {
                while (keepRunning)
                {
                    try
                    {
                        if ((shortPool.QueuedProcesses + longPool.QueuedProcesses) == 0 || LastRuntime.AddMilliseconds(QueryWaitTime) > DateTime.Now)
                        {
                            LastRuntime = DateTime.Now;

                            cmd = new SqlCommand("EXEC jmjsys_ready_server_services", sqlCon);
                            // EXECUTE SP TO GET WAITING SERVICES
                            try
                            {
                                rdr = cmd.ExecuteReader();
                            }
                            catch (SqlException sexc)
                            {
                                log.WriteEntry(sexc.ToString() + Environment.NewLine + Environment.NewLine + cmd.CommandText, EventLogEntryType.Error);
                                continue;
                            }
                            catch (InvalidOperationException ioc)
                            {                            // Likely DB disconnect
                                log.WriteEntry(ioc.ToString(), EventLogEntryType.Error);
                                goto CONNECT;
                            }
                            catch (Exception exc)
                            {
                                log.WriteEntry(exc.ToString(), EventLogEntryType.Error);
                                continue;
                            }
                            try
                            {
                                while (rdr.Read())
                                {
                                    string ls_arg;
                                    string ls_item_type;
                                    ls_item_type = rdr["item_type"].ToString().ToUpper();
                                    if (ls_item_type == "SERVICE")
                                    {
                                        ls_arg = "WPITEM=" + rdr["patient_workplan_item_id"].ToString();
                                    }
                                    else
                                    {
                                        ls_arg = ls_item_type + "=" + rdr["patient_workplan_item_id"].ToString();
                                    }

                                    ProcessInfo newPI = new ProcessInfo(System.IO.Path.Combine(path, "EproServer.exe"), ls_arg);

                                    if (!rdr.IsDBNull(rdr.GetOrdinal("retries")))
                                    {
                                        // ADD WAITING RETRY SERVICES TO LONG QUEUE
                                        longPool.Enqueue(newPI);
                                    }
                                    else
                                    // ADD WAITING FIRST TIME SERVICES TO SHORT QUEUE
                                    // IF IT HAS NOT BEEN MOVED TO LONG QUEUE ALREADY
                                    if (!longPool.IsRunning(newPI))
                                    {
                                        shortPool.Enqueue(newPI);
                                    }
                                }
                            }
                            catch (SqlException sexc)
                            {
                                log.WriteEntry(sexc.ToString(), EventLogEntryType.Error);
                                continue;
                            }
                            rdr.Close();
                        }
                        Thread.Sleep(MainServiceLoopSleepTime);
                    }
                    catch (Exception exc)
                    {
                        try
                        {
                            rdr.Close();
                        }
                        catch {}
                        log.WriteEntry(exc.ToString(), EventLogEntryType.Error);
                    }
                }
            }
            finally
            {
                //EPSEventLog.WriteEntry("Exited main loop in ServiceThreadManager");
            }
            sqlCon.Close();
        }
Exemplo n.º 12
0
        public static string getServiceInfo()
        {
            if (null == sm)
            {
                throw new Exception("No instance of ServiceManager is running");
            }

            System.Data.SqlClient.SqlConnection con = InternalMethods.GetNewConnection(sm.dbConInfo[0], sm.dbConInfo[1]);
            SqlCommand cmd = null;

            try
            {
                System.IO.MemoryStream   ms = new System.IO.MemoryStream();
                System.Xml.XmlTextWriter w  = new System.Xml.XmlTextWriter(ms, System.Text.Encoding.UTF8);

                w.WriteStartDocument();
                w.WriteStartElement("ServiceInfo");

                if (sm.serviceWrappers != null && sm.serviceWrappers.Length > 0)
                {
                    foreach (ServiceWrapper sw in sm.serviceWrappers)
                    {
                        w.WriteStartElement("Service");
                        try
                        {
                            w.WriteElementString("ID", sw.ServiceID.ToString());
                            cmd = new SqlCommand("SELECT service_name FROM o_server_component WHERE service_id = " + sw.ServiceID.ToString(), con);
                            string serviceName = (string)cmd.ExecuteScalar();
                            w.WriteElementString("Description", serviceName);
                            w.WriteElementString("PID", sw.PID.ToString());
                            w.WriteElementString("RunningTime", Math.Round(sw.AgentProcess.Runtime.TotalHours, 2).ToString() + " hours");
                            w.WriteElementString("Memory", sw.CurrentMemoryMB.ToString() + " MB");
                            w.WriteElementString("MaxMemory", Math.Round(((double)sw.AgentProcess.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                        }
                        catch {}
                        w.WriteEndElement();
                    }
                }

                if (sm.serviceThreadManager != null)
                {
                    ServiceThreadManager stm = sm.serviceThreadManager;

                    w.WriteStartElement("ProcessPools");

                    w.WriteStartElement("ProcessPool");
                    w.WriteAttributeString("type", "short");
                    w.WriteElementString("MaxProcesses", stm.sMaxRunningProcesses.ToString());
                    w.WriteStartElement("QueuedProcesses");
                    if (stm.sQueuedProcessArray != null && stm.sQueuedProcessArray.Length > 0)
                    {
                        foreach (ProcessInfo pi in stm.sQueuedProcessArray)
                        {
                            w.WriteStartElement("QueuedProcess");
                            try
                            {
                                w.WriteElementString("Application", pi.Application);
                                w.WriteElementString("Arguments", pi.Arguments);
                            }
                            catch {}
                            w.WriteEndElement();
                        }
                    }
                    w.WriteEndElement();
                    w.WriteStartElement("RunningProcesses");
                    if (stm.sRunningProcessArray != null && stm.sRunningProcessArray.Length > 0)
                    {
                        foreach (AgentProcess ap in stm.sRunningProcessArray)
                        {
                            w.WriteStartElement("RunningProcess");
                            // WPItem
                            try
                            {
                                if (ap.Arguments.IndexOf("WPITEM") > -1)
                                {
                                    w.WriteElementString("Type", "WPItem");
                                    w.WriteElementString("ID", ap.TaskId.ToString());
                                    cmd = new SqlCommand("SELECT description FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con);
                                    string wpitem = (string)cmd.ExecuteScalar();
                                    w.WriteElementString("Description", wpitem);
                                    w.WriteElementString("User", ap.TaskUser);
                                    w.WriteElementString("PID", ap.ProcessId.ToString());
                                    w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    cmd = new SqlCommand("SELECT retries FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con);
                                    string retries = cmd.ExecuteScalar().ToString();
                                    w.WriteElementString("Retries", retries);
                                }
                                // Scheduled
                                else if (ap.Arguments.IndexOf("SCHEDULE") > -1)
                                {
                                    w.WriteElementString("Type", "Scheduled");
                                    w.WriteElementString("ID", ap.TaskId.ToString());
                                    cmd = new SqlCommand("SELECT service FROM o_service_schedule WHERE service_sequence = " + ap.TaskId.ToString(), con);
                                    string service = (string)cmd.ExecuteScalar();
                                    w.WriteElementString("Description", service);
                                    w.WriteElementString("User", ap.TaskUser);
                                    w.WriteElementString("PID", ap.ProcessId.ToString());
                                    w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    w.WriteElementString("Retries", null);
                                }
                            }
                            catch {}
                            w.WriteEndElement();
                        }
                    }
                    w.WriteEndElement();
                    w.WriteEndElement();

                    w.WriteStartElement("ProcessPool");
                    w.WriteAttributeString("type", "long");
                    w.WriteElementString("MaxProcesses", stm.lMaxRunningProcesses.ToString());
                    w.WriteStartElement("QueuedProcesses");
                    if (stm.lQueuedProcessArray != null && stm.lQueuedProcessArray.Length > 0)
                    {
                        foreach (ProcessInfo pi in stm.lQueuedProcessArray)
                        {
                            w.WriteStartElement("QueuedProcess");
                            try
                            {
                                w.WriteElementString("Application", pi.Application);
                                w.WriteElementString("Arguments", pi.Arguments);
                            }
                            catch {}
                            w.WriteEndElement();
                        }
                    }
                    w.WriteEndElement();
                    w.WriteStartElement("RunningProcesses");
                    if (stm.lRunningProcessArray != null && stm.lRunningProcessArray.Length > 0)
                    {
                        foreach (AgentProcess ap in stm.lRunningProcessArray)
                        {
                            w.WriteStartElement("RunningProcess");
                            try
                            {
                                // WPItem
                                if (ap.Arguments.IndexOf("WPITEM") > -1)
                                {
                                    w.WriteElementString("Type", "WPItem");
                                    w.WriteElementString("ID", ap.TaskId.ToString());
                                    cmd = new SqlCommand("SELECT description FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con);
                                    string wpitem = (string)cmd.ExecuteScalar();
                                    w.WriteElementString("Description", wpitem);
                                    w.WriteElementString("User", ap.TaskUser);
                                    w.WriteElementString("PID", ap.ProcessId.ToString());
                                    w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    cmd = new SqlCommand("SELECT retries FROM p_patient_wp_item WHERE patient_workplan_item_id = " + ap.TaskId.ToString(), con);
                                    string retries = cmd.ExecuteScalar().ToString();
                                    w.WriteElementString("Retries", retries);
                                }
                                // Scheduled
                                else if (ap.Arguments.IndexOf("SCHEDULE") > -1)
                                {
                                    w.WriteElementString("Type", "Scheduled");
                                    w.WriteElementString("ID", ap.TaskId.ToString());
                                    cmd = new SqlCommand("SELECT service FROM o_service_schedule WHERE service_sequence = " + ap.TaskId.ToString(), con);
                                    string service = (string)cmd.ExecuteScalar();
                                    w.WriteElementString("Description", service);
                                    w.WriteElementString("User", ap.TaskUser);
                                    w.WriteElementString("PID", ap.ProcessId.ToString());
                                    w.WriteElementString("RunningTime", Math.Round(ap.Runtime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("MaxRunningTime", Math.Round(ap.MaxRuntime.TotalMinutes, 2).ToString() + " minutes");
                                    w.WriteElementString("Memory", Math.Round(((double)ap.MemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    w.WriteElementString("MaxMemory", Math.Round(((double)ap.MaxMemoryUsage) / Math.Pow(2d, 20d), 2).ToString() + " MB");
                                    w.WriteElementString("Retries", null);
                                }
                            }
                            catch {}
                            w.WriteEndElement();
                        }
                    }
                    w.WriteEndElement();
                    w.WriteEndElement();
                    w.WriteEndElement();
                }
                w.WriteEndElement();
                w.WriteEndDocument();
                w.Flush();

                ms.Position = 0;

                System.IO.StreamReader sr = new System.IO.StreamReader(ms, System.Text.Encoding.UTF8);
                string results            = sr.ReadToEnd();
                sr.Close();

                return(results);
            }
            catch (Exception exc)
            {
                EPSEventLog.WriteEntry(exc.ToString(), EventLogEntryType.Error);
                return(null);
            }
            finally
            {
                try{ con.Close(); }
                catch {}
            }
        }