title: How to solve this error "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection"
body: <p>I'm trying to use the same object in two differebt dbContext. I got this error</p>
  
  <blockquote>
    <p>The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.</p>
  </blockquote>
  
  <p>What are the possible causes of this error?</p>
  
  <pre><code>public string ValidateNXT_MODULE_DETAILS_PHARMACY(int id)
  {
      long? ValCounter = 0;
      string prepQu = Constante.CurrentUser.LOG_USER; ;
      DateTime dateQu = DateTime.Today;
      NXT_MODULE_DETAILS_PHARMACY module = new NXT_MODULE_DETAILS_PHARMACY();
  
      try
      {
          using (CaseManagerEntities db = new CaseManagerEntities())
          {                    
              NXT_MODULE_DETAILS_PHARMACY cmd = db.NXT_MODULE_DETAILS_PHARMACY.Find(id);                    
              module = cmd;
          }                
  
          using (PHStockEntities db = new PHStockEntities())
          {
              using (TransactionScope t = new TransactionScope())
              {
                  NXT_PH_COUNTER Counter = db.NXT_PH_COUNTER.Where(nat =&gt; nat.TYPE_CHOIX == 301).First();
                  ValCounter = Counter.Value;
                  Counter.Value = ValCounter + 1;                        
  
                  foreach (var detail in module.NXT_MODULE_DETAILS_PHARMACY_DETAIL.ToList())
                  {
  
                      NXT_PH_CHOIX_MODULE choix = db.NXT_PH_CHOIX_MODULE.Where(nat =&gt; nat.TYPE_CHOIX == 301).First();
                      NXT_ASS_ART_LOT_DEP_EC association = db.NXT_ASS_ART_LOT_DEP_EC.Where(nat =&gt; nat.ID_ARTICLE == detail.ID_LIST_PH_DET &amp;&amp; nat.ID_LIST_DEPOT == module.DEPOT).First();
  
                      decimal? QTE = 0;
                      if (choix.SIGNE_STOCK == "P")
                      {
                          QTE = detail.QTE_PH_DET;
                      }
                      else if (choix.SIGNE_STOCK == "M")
                      {
                          QTE = decimal.Negate(decimal.Parse(detail.QTE_PH_DET.ToString()));
                      }
                      switch (choix.CHAMP_STOCK)
                      {
                          case "STOCK_VENTE":
                              association.STOCK_VENTE = association.STOCK_VENTE + QTE;
                              break;
                          case "STOCK_ACHAT":
                              association.STOCK_ACHAT = association.STOCK_ACHAT + QTE;
                              break;
                          case "STOCK_MOUVEMENT":
                              association.STOCK_MOUVEMENT = association.STOCK_MOUVEMENT + QTE;
                              break;
                          case "STOCK_ETAGE":
                              association.STOCK_ETAGE = association.STOCK_ETAGE + QTE;
                              break;
                      }
                  }
  
                  db.SaveChanges();
                  t.Complete();
              }
          }
  
          using (CaseManagerEntities db = new CaseManagerEntities())
          {
              using (TransactionScope t = new TransactionScope())
              {
                  module.NBR_QUITTANCE = ValCounter.ToString();
                  module.DATE_QUITTANCE = dateQu;
                  module.PREPART_QUITTANCE = prepQu;
                  module.STATUT = 3;
                  dbCaseManager.SaveChanges();
                  t.Complete();
              }
          }
          return ValCounter.ToString() + ";" + prepQu + ";" + dateQu.Date;
      }
      catch (Exception e)
      {
          return "ERROR";
      }        
  }
  </code></pre>