title: Exception - "This MySqlConnection is already in use" when using MYSql server. However the same Linq query works fine with MS SQL Server
body: <p>I am developing a Quality Assurance Application using the .NET Core framework (5.0). Initially, I have used MS SQL Server DB and it was working fine. However, now due to requirement change, I have now moved to MYSQL Server.</p>
  <p>I have successfully integrated the database using the code-first approach (Entity framework). Also, I am using the NuGet package <strong>Pomelo.EntityFrameworkCore.MySql</strong> and everything works just fine except the below-mentioned Linq query where I am getting an exception - <strong>This MySqlConnection is already in use</strong>.</p>
  <pre><code>public List&lt;ErrorMessage&gt; GetErrorMessage(int productId)
  {
      List&lt;ErrorMessage&gt; localList = new List&lt;ErrorMessage&gt;();
      var product = _db.Products.Where(a =&gt; a.ProductId == productId).FirstOrDefault();
      if (product != null)
      {
  
          var products = _db.Products
              .Where(q =&gt; q.ProductName.ToLower() == product.ProductName.ToLower()).Select(e =&gt; e.ProductId);
          foreach (var item in products)
          {
              var errormessage = _db.ErrorMessageTracks.Where(q =&gt; q.ProductId == item).Select(e =&gt; e.ErrorMessage);
              foreach (var msg in errormessage)
              {
                  if (!localList.Select(q =&gt; q.ErrorMessageId).Contains(msg.ErrorMessageId))
                  {
  
                      localList.Add(msg);
                  }
              }
          }
  
      }
      return localList;
  }
  </code></pre>
  <p>I have referred to other similar questions but I couldn't resolve the issue as I am not sure how to close the SQL connection as I am using Linq Query and not the actual SQL Join. Any help would be appreciated!</p>