[Solved] Cannot open database requested by the login. The login failed. Login failed for user IIS APPPOOL

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.

Problem

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.

Solution

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.

Conclusion

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.

  1. This issue which discussed in this article.
  2. Cannot open database requested by the login. The login failed. Login failed for user ‘NT AUTHORITY\LOCAL SERVICE’
  3. Microsoft.Data.SqlClient.SqlException (0x80131904): The INSERT permission was denied on the object, database, schema ‘dbo’
Sreenivasa Rangan TR
Sreenivasa Rangan TR

Software professional with 7+ years of experience in all phases of software development with robust problem-solving skills and proven experience in creating and designing software in a test-driven environment.

Leave a Reply