Can not connect to SQL Server from web-site on IIS?

I remember I had to fix this issue about a year ago. And I completely forgotten how to do this. And the same problem strikes again.

The issue was with a web-site (MVC5, 4.5.1 .Net) running on IIS. And I had an issue when trying to get data from SQL Server.
The connection did not go through whatever I did.

The fix was quite simple. All I needed to do is to change the AppPool underlying user to be “NetworkService” instead of “ApplicationPoolIdentity”:

  1. In IIS, in list of Application Pools find the one which works with your site.
  2. In Advanced Settings (link on right) for that AppPool find Section Process Model and Identity setting first
  3. Change Identity to be NetworkService
  4. Restart AppPool and the web-site.

This is possibly one of the reasons that can cause the issue. There is a million of other reasons this can happen, but I have checked most of them before started semi-randomly poking about with app pools and IIS settings.