title: InvalidOperationException: The connection was not closed. The connection's current state is connecting
body: <p>I have this following code written using Codesmith (similar to Entity Framework).
  I am getting the exception mentioned below after the code.
  And I don't get this exception every time. This application is WPF and Multi threaded. </p>
  
  <pre><code>public Dictionary&lt;string, string&gt; GetDelimiterOfAnalyser()
  {
      Dictionary&lt;string, string&gt; delimiters = new Dictionary&lt;string, string&gt;();
      try
      {
          foreach (var delimiter in dataContext.DataSource.Where(a =&gt; a.TypeId == 1).ToList())
          {
              if (!delimiters.ContainsKey(delimiter.Name))
              {
                  delimiters.Add(delimiter.Name, delimiter.Delimiter.Value);
              }
          }
      }
      catch (Exception ex)
      {
          logger.Error("Error in GetDelimiterOfAnalyser. Ex: " + ex);
      }
      return delimiters;
  }
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>2018-07-08 11:41:32.4889 ERROR : Error in GetDelimiterOfAnalyser. Ex: System.InvalidOperationException: The connection was not closed. The connection's current state is connecting.
     at System.Data.ProviderBase.DbConnectionClosedConnecting.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
     at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
     at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
     at System.Data.SqlClient.SqlConnection.Open()
     at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
     at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
     at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
     at System.Data.Linq.SqlClient.SqlProvider.CompiledQuery.Execute(IProvider provider, Object[] arguments)
     at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.ExecuteKeyQuery(Object[] keyValues)
     at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.Execute(Object instance)
     at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
     at System.Data.Linq.EntityRef`1.get_Entity()
     at ReconConfig.Data.DataSource.get_Delimiter() in C:\Users\*\OHS.Reconn.DataAccessLayer\Entities\DataSource.Generated.cs:line 407
  </code></pre>