public void CreateMhistory(String message)
        {
            try
            {
                Message_History history = new Message_History();
                history.DateTime = System.DateTime.Now;
                history.Message = message;
                Message m = new Message(message);
                history.PatID = m.getElement("PID", 3);
                history.PatName = m.getElement("PID", 5);
                history.messageid = m.getElement("MSH", 9);

                //using (_magDb)
                //{
              var      _magDb = new MagLink_engineEntities();
                    _magDb.Message_History.Add(history);
                    _magDb.SaveChanges();
                  //  _magDb.Dispose();
                //}
            }
            catch (Exception ex)
            {
                    ErrorHandler._ErrorHandler.LogError(ex, "Error entering data in the message history table");

            }
            
        }
     public void SaveChangesMhistory(Message_History mhistory)
 {
        try
         {
             //using (_magDb)
             //{
               var  _magDb = new MagLink_engineEntities();
                 //_magDb.Message_History.Attach(mhistory);
             _magDb.Entry(mhistory).State = mhistory.mhistID == 0 ? EntityState.Added : EntityState.Modified;
                 _magDb.SaveChanges();
                 //_magDb.Dispose();
             //}
         }
         catch (Exception ex)
         {
             ErrorHandler._ErrorHandler.LogError(ex, "Error saving changes to queue call");
         }
     }