title: Getting a 'System.InvalidOperationException' when changing the connection string for connecting to a database C#
body: <p>I am getting an unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll when I run my application.</p>
  <p>My application is a basic C# application using entity framework code first approach and I am trying to connect to a database.</p>
  <p>The following code is used to add data to the database (which worked before I added a connection string to the App.Config file.</p>
  <pre><code>static void Main(string[] args)
      {
          using (var context = new BehaviourContext())
          {
              Behaviour behaviour = new Behaviour()
              {
                  Name = &quot;test behaviour&quot;,
                  Activation_Threshold = 90,
                  Currently_Executing = false,
                  Preconditions_Met = false,
                  Priority = 0.9f
              };
              context.Behaviours.Add(behaviour);
              context.SaveChanges();
          }
      }
  </code></pre>
  <p>This is my context class:</p>
  <pre><code>public class BehaviourContext: DbContext
  {
      public BehaviourContext(): base(&quot;name=BehaviourConnectionString&quot;)
      {
  
      }
      public DbSet&lt;Behaviour&gt; Behaviours { get; set; }
  }
  </code></pre>
  <p>This was working fine until I added a connection string:</p>
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name=&quot;BehaviourConnectionString&quot;
  connectionString=&quot;Data Source=.;Initial Catalog=BehaviourDB-ByConnectionString;Integrated Security=true&quot;
  providerName=&quot;System.Data.SqlClient&quot;/&gt;
  </code></pre>
    
  <p>And this is the full error I get when I run the application:</p>
  <blockquote>
  <p>An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll</p>
  <p>Additional information: The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe.</p>
  </blockquote>
  <p>Any help, hints or tip will be greatly appreciated. :)</p>