The IIS exception Cannot open database requested by the login. The login failed. Login failed for user IIS APPPOOL is a common issue when we host an application for the first time in the IIS server and try to connect the database via the application.
The issue clearly indicates that for the user IIS APPPOOL application is not allowed to make the database connection. As user IIS APPPOOL not able to authenticate. To be more specific, I am using windows authentication here to login into Microsoft SQL Server via ASP.NET Core application.
It is recommended that using Windows Authentication to login into the database via application with Trusted_Connection=True in the production environment for high security. In this case, we supposed to use the LocalService as an identity for AppPool. To change identity, first, we need to goto our website and find out which AppPool our website is using as shown below.
For this example my Application Pool name is JobsSocial. Select and right click on website application pool. Then go to Advanced Settings from the menu.
In Advanced Settings by default, ApplicationPoolIdenty is selected as Identity as shown below image.
From the dropdown select LocalService as Identity as shown in below image. To complete this settings hit Ok button.
When hosting a web application for the first time in IIS Server, we may face a couple of issues to make it work successfully. I also faced three issues when I hosted my ASP.Net Core web application for the first time on the IIS web server. Out of three issues, Cannot open database requested by the login. The login failed. Login failed for user IIS APPPOOL was the first issue and I have listed the other two issues also with the appropriate solution below.