title: Adding an Entity Framework connection string as a variable in Application Settings
body: <p>I have this auto-generated connection string in my app.config file.  This was produced by making a database-first model in Entity Framework:</p>
  
  <pre><code>&lt;add name="HalloweenContext" connectionString="metadata=res://*/HalloweenDbModel.csdl|
                                                      res://*/HalloweenDbModel.ssdl|
                                                      res://*/HalloweenDbModel.msl;
                           provider=System.Data.SqlClient;
                           provider connection string=&amp;quot;
                           data source=localhost\sqlexpress;
                           initial catalog=Halloween;
                           integrated security=True;
                           MultipleActiveResultSets=True;
                           App=EntityFramework&amp;quot;"
   providerName="System.Data.EntityClient" /&gt;
  </code></pre>
  
  <p>I've been instructed to take that connection string and put it in the application settings (image is to illustrate the application settings page):</p>
  
  <p><img src="https://i.stack.imgur.com/MJ9ZV.png" alt="enter image description here"></p>
  
  <p>I've taken this section and cut/pasted it into a settings variable called "HalloweenContext" and also changed the <code>&amp;quote;</code> to a single-quote:</p>
  
  <pre><code>"metadata=res://*/HalloweenDbModel.csdl|
            res://*/HalloweenDbModel.ssdl|
            res://*/HalloweenDbModel.msl;
            provider=System.Data.SqlClient;
            provider connection string=';
            data source=localhost\sqlexpress;
            initial catalog=Halloween;
            integrated security=True;
            MultipleActiveResultSets=True;
            App=EntityFramework';"
   providerName="System.Data.EntityClient"
  </code></pre>
  
  <p>However, when I paste this above selection into the application settings variable for HallowContext, I get the following error message:</p>
  
  <p><img src="https://i.stack.imgur.com/Lzwrl.png" alt="enter image description here"></p>
  
  <p>I've checked the connection string and rechecked it, but I can't figure out what's wrong with it.  I've removed quotes, added quotes, etc.  but nothing seems to work for me.</p>
  
  <p>I'm wondering if, perhaps, since this is an EF connection string, that I'm putting it into the application settings incorrectly?</p>
  
  <p>UPDATE: After using the new data connection string outlined in the answer below, I am now getting a new error:</p>
  
  <blockquote>
    <p>The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development.  This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection...</p>
  </blockquote>
  
  <p>So, I'm thinking that I may not be able to use this context in lieu of my db-first context.  But, I also can't seem to use my db-first context as it is, so I'm at a standstill.  I'll keep looking for a solution, and I do appreciate the help given so far.</p>
  
  <p>As an added note, I'll restate that the original connection string works fine and is in the app.config file.  However, I've been instructed to add it to the application settings.  Personally, I feel that if it works in the app.config file, then that should be enough, but we've been instructed to use the connection string by adding it to the application settings and using it like <code>connectionString = Settings.Default.HaloweenContext</code>.  The ultimate goal is to have many connection strings set up in the application settings that we can use.</p>
  
  <p>SIDE NOTE:  I'm of the belief that using multiple named connection strings in the app.config file is the way to go.  Is there any advantage to adding those connection strings as application settings instead of just manually adding them to the app.config file?</p>