title: How to set-up SQL Server / IIS 7.0 to allow ASP.NET MVC website to access to database?
body: <p>I have built an ASP.NET MVC 2 website that I am hosting with Rackspace Cloud Server using IIS 7.0. </p>
  
  <p>When I try to test the website under localhost with IIS 7.0 on the server I get an error page. This comes from the SQL logs (I am using SQL Web Edition):</p>
  
  <pre><code>Error: 18456, Severity: 14, State: 11
  Login failed for user 'IIS APPPOOL\DefaultAppPool'. Reason: Token-based server access validation failed with an infrastructure error. Check for previous errors. [CLIENT: &lt;local machine&gt;]
  </code></pre>
  
  <p>My website works fine on my home PC so the issue is something to do with connecting with the database.</p>
  
  <p>Having researched the error message code it suggests that I have a valid DB login but server access has failed. I did a stack of reading around this on various forums (incl. stackoverflow / serverfault) and here is what I have tried, none of which have solved the issue:</p>
  
  <ol>
  <li><p><strong>Set up new login using SQL Server Authentication</strong>. I created a new login in SQL and gave correct access rights to my DB. I used following connection string in web config:</p>
  
  <p>Data Source=myServer;Initial Catalog=myDB;User Id=myUsername;Password=myPassword;</p></li>
  <li><p><strong>Create new login as <code>IIS APPPOOL\DefaultAppPool</code></strong>. I created new login in SQL with correct access rights and used windows authentication. Connection string as follows:</p>
  
  <p>Server=myServer;Database=myDataBase;Trusted_Connection=True;</p></li>
  <li><p><strong>Use existing network login <code>NT AUTHORITY\NETWORK SERVICE</code></strong>. I mapped this user to my database with correct access rights. Connection string as follows:</p>
  
  <p>Server=myServer;Database=myDataBase;Trusted_Connection=True;</p></li>
  </ol>
  
  <p>These appeard to be the main options as I read through material online. Finally, here as some other things that may be helpful:</p>
  
  <ul>
  <li>Setting SQL to <strong>run as administrator</strong> did not solve the issue</li>
  <li>Turning off <code>UAC</code> did not help</li>
  <li>My application pool is using <strong>ApplicationPoolIdentity</strong> (best for security reasons)</li>
  </ul>
  
  <p>In short, my website won't start because it cannot get an object from the DB so throws an error. The issue is that access rights to the server are not set correctly. I cannot work out what configuration of SQL login / connection string / domain access rights I need.</p>
  
  <p>This has vexed me for 3 weeks - can you spare 5 mins to help me please?</p>