title: SQL won't connect after deploying
body: <p>I recently deployed my website on IIS (LocalDB). But whenever I try to run the website, the SQL fails to connect. I've been through hundreds of posts/articles now but I am unable to resolve it.</p>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>A network-related or instance-specific error occurred while
    establishing a connection to SQL Server. The server was not found or
    was not accessible. Verify that the instance name is correct and that
    SQL Server is configured to allow remote connections. (provider: SQL
    Network Interfaces, error: 50 - Local Database Runtime error occurred.
    Cannot create an automatic instance. See the Windows Application event
    log for error details. )</p>
  </blockquote>
  
  <p><strong>Windows Application event log</strong></p>
  
  <blockquote>
    <p>Windows API call SHGetKnownFolderPath returned error code: 5. Windows
    system error message is: Access is denied. Reported at line: 422.</p>
  </blockquote>
  
  <p>Second log -</p>
  
  <blockquote>
    <p>Cannot get a local application data path. Most probably a user profile
    is not loaded. If LocalDB is executed under IIS, make sure that
    profile loading is enabled for the current user.</p>
  </blockquote>
  
  <p><strong>My Connection Strings</strong> (tried both)-</p>
  
  <pre><code>&lt;appSettings&gt;
      &lt;add key="ConnectionString" value="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=test;Integrated Security=True" /&gt;
      &lt;!--&lt;add key="ConnectionString" value="data source=(LocalDB)\MSSQLLocalDB;UID=SOME_USERNAME;PWD=SOME_PASSWORD;initial catalog=test;connection timeout=30"/&gt;--&gt;
    &lt;/appSettings&gt;
  </code></pre>
  
  <p>I tried editing <a href="https://stackoverflow.com/a/32399846/4046274">applicationHost.config</a>. <br>
  <a href="http://jaryl-lan.blogspot.in/2016/06/localdb-connecting-to-localdb-failed.html" rel="noreferrer">Load User Profile</a> was already True for me <br></p>
  
  <p>My ApplicationHost.config file</p>
  
  <pre><code> &lt;applicationPools&gt;
  
              &lt;add name="Classic .NET AppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" /&gt;
              &lt;add name=".NET v2.0 Classic" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" /&gt;
              &lt;add name=".NET v2.0" managedRuntimeVersion="v2.0" /&gt;
              &lt;add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" /&gt;
              &lt;add name=".NET v4.5" managedRuntimeVersion="v4.0" /&gt;
              &lt;add name="ASP.NET v4.0" managedRuntimeVersion="v4.0"&gt;
  
              &lt;add name="DefaultAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated"&gt;
             &lt;processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" /&gt;
              &lt;/add&gt;
          &lt;/applicationPools&gt;
  </code></pre>
  
  <p><strong>My IIS manager</strong> - 
  <a href="https://i.stack.imgur.com/62TBm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/62TBm.png" alt="enter image description here"></a></p>
  
  <p><strong>DefaultApplicationPool</strong> -</p>
  
  <p><a href="https://i.stack.imgur.com/RyFb8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/RyFb8.png" alt="enter image description here"></a></p>
  
  <p><strong>My web app configuration</strong> - <br><a href="https://i.stack.imgur.com/cgUmK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cgUmK.png" alt="enter image description here"></a></p>
  
  <p><strong>App Pool permission</strong> <br> 
  <a href="https://i.stack.imgur.com/LwY00.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LwY00.png" alt="enter image description here"></a></p>
  
  <p>EDIT -</p>
  
  <p>Added IIS Apppool using</p>
  
  <pre><code>icacls c:\inetpub\wwwroot /grant "IIS APPPOOL\DefaultAppPool":(OI)(CI)(RX)
  </code></pre>
  
  <p>Still not able to connect.</p>
  
  <p>Any help is appreciated. </p>
  
  <p>I am on Windows 10 using Visual Studio 2015 with SQL Server 2016.</p>