title: "Connection String 'RgaAppDBEntities' could not be found in App.Config" preventing me from adding a WinForm User Control
body: <p>I am creating a WinForms application using Entity Framework 6 and DevExpress UI Components. I've been developing this application successfully for about 2 months, and today I needed to add a new user control to the main window. To my surprise, the designer of the main window displayed an error screen with a couple of exceptions. I clicked &quot;Ignore and Continue&quot; (Which may be the source of my problems).</p>
  <p>So here is the issue: After clicking ignore and continue, apparently the designer removed two of my custom user controls (which were the two controls that have implemented Entity Framework so far). When I try to add the user control back to the designer,
  <a href="https://i.stack.imgur.com/dIozP.png" rel="nofollow noreferrer">an error pops up</a> stating that it cannot create the component, and it cannot find the connection string in the application config file.</p>
  <p>I've determined the reason I cannot add the user control is because the two user controls causing the issue create an instance of &quot;RgaAppDBEntities&quot;, which is the database model I am using.</p>
  <p>My data model is in a separate class library project. The App.Config file in both the class library and the WinForms project have:</p>
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name=&quot;RgaAppDBEntities&quot; connectionString=&quot;sensitive connection string information generated from database first model&quot; providerName=&quot;System.Data.EntityClient&quot; /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  <p>The Db Context class constructor looks like:</p>
  <pre><code>public RgaAppDBEntities()
          : base(&quot;name=RgaAppDBEntities&quot;)
      {
      }
  </code></pre>
  <p>Getting rid of the &quot;name=&quot; results in a UnintentionalCodeFirstException(), so that tells me that for some reason, the WinForms project cannot actually find the connection string named RgaAppDBEntities in the config file, and I am out of ideas.</p>
  <p>Finally, I completely got rid of the data model and regenerated the entire model again, and reimplemented everything I needed to, but it still cannot find the connection string in the app.config files.</p>
  <p>What could be the cause of this issue, and how can I fix it?</p>
  <p><strong>SOLUTION</strong></p>
  <p>GertArnold's suggestion was correct: when you try to make EntityFramework read app.config during design time, it will complain and not allow you to through exceptions.</p>
  <p>In my case, I initialized the database contexts in the constructor of each control's viewmodel, which of course was initialized at run time. As a work around, I just created a method that initializes the database contexts that can only be called at run time. Works like a charm.</p>