title: Entity Framework Code First ignoring connection string, using IIS instead
body: <p>I have a web app that I've created using Entity Framework Code First. In setting it up I have managed to match my DB connection string to my DBContext by specifying the full namespace and class of the DBContext as the name of the connection string.</p>
  <pre><code>&lt;add name=&quot;MyClassProject.EfDbContext&quot;  connectionString=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=true;User Id=MyUsername;Password=MyPassword;&quot; providerName=&quot;System.Data.SqlClient&quot;/&gt;
  </code></pre>
  <p>Initially when I set up the project, I just had it created in c:\inetpub\wwwroot, and just ran it through Visual Studio. Everything worked fine.</p>
  <p>Now I'm trying to have the code build to a separate website folder, and have the website run as it's own website and app pool in IIS. I've set up the website, and my hosts file but when I went to run it I received the following error.</p>
  <blockquote>
  <p>Cannot open database &quot;MyDatabase&quot; requested by the login. The login failed.</p>
  <p>Login failed for user 'IIS APPPOOL\MyAppPool'.</p>
  </blockquote>
  <p>I'm wondering why this is happening, as I seem to be specifying the security username and password to use for the DB in my connection string....so why is it trying to connect as the app pool that my website is running in?</p>
  <p>Also, how can I fix this, without having to give MyAppPool (or Network Service if I changed it to that) DB permissions in SQL Server?</p>
  <p><strong>Update:</strong> I should've mentioned that I initialise my DBContext class using:</p>
  <pre><code>namespace MyClassProject 
  { 
      public class EfDbContext : DbContext 
      { 
          public EfDbContext() : base (&quot;MyDatabase&quot;) 
          {
          }
      }
  }
  </code></pre>