Introduction

I am here highlighting the difficulty System.Data.Sqlclient.Sqlexception:Login failed for user iis apppool \default apppool usually encountering whereas working with ASP.Net application with IIS. I actually have been engaged on web application. Everything was going fine however suddenly I got the error “System.Data.SqlClient.SqlException was unhandled by user code:  Login failed for user 'IIS APPPOOL\DefaultAppPool’” and database connection couldn't open.

Error Description:

System.Data.SqlClient.SqlException was unhandled by user code:  Login failed for user 'IIS APPPOOL\DefaultAppPool

Know How About Application Pool Identity 

Application Pool Identity corresponds to security of your website whereas running your website under IIS. Application Pool Identity runs your website unique account. Network service is IIS default identity, it doesn't need password so caused low prevailed. You'll reconfigure IIS Application Pool Identities as per your specific demand.
I have below provided steps to resolve this issue.

Step 1: Go to Run (Win+R Shortcut) and then type “inetmgr” and hit “OK” button.

Step 2: Now you are in the IIS and now expand left pane and click on the “Application Pools

Login failed for user iis apppool
IIS (Application Pool)



Step 3: Now you can select “DefaultAppPool” and click on “Advance Settings”.

Step 4: Now open “Advance Settings” window and scroll down window to “Process Model”. Under the “Process Model” section select “Identity” property. Select “LocalSystem” from drop down list. Local Service works the computer on local system & over the local computer.

Application Pool Identity
Application Pool Identity
Step 5: Process Model Element was introduced with IIS 7.0
Step 6: "ApplicationPoolIdentity" runs under dynamically created application pools. identity account. "ApplicationPoolIdentity" pool access the resources from IIS AppPool\<AppPool>, It's nice feature to administrator who will impose security privileges to end users. This is often run mostly for remotely or public accessing the website.

ApplicationPoolIdentity
ApplicationPoolIdentity

Step 7: Now Click on "OK" button, you have to take optional Step 4 or step 6 to run your application smoothly.

OK

By Command line, we can also provide complete access to DefaultAppPool (if Already complete access to production server)


ICACLS test.txt /grant "IIS AppPool\DefaultAppPool":F

Summary

Given above steps will provide you complete helpline, the way to resolve the error of “Login failed for user 'IIS APPPOOL\DefaultAppPool’”. Application pool identity need default permission to run your website under IIS perfectly for specific account access group.  I hope steps provided above will work to resolve your problem perfectly.

Relevant Reading:

Videologin failed for user