I have an ASP.net MVC web app which uses Windows Authentication and that part is working well. I introduced a SQL Server database to this web app but I'm having problems accessing this database.
I performed the following actions:
- Create database called "MyDatabase" in SQL Server Express.
- Registered my website to use IIS rather than IIS Express.
- Created an AppPool in IIS with Integrated Security and called it "WebAppAppPool"
- Associated "WebAppAppPool" to my website.
- Added "WebAppAppPool" to SQL Server using "IIS APPPOOL\WebAppAppPool"
- Set the User Mapping in SSMS to grant access to "WebAppAppPool" and selected db_datareader and db_datawriter to "MyDatabase" database.
And yet I'm still getting this error:
Cannot open database "MyDatabase" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\WebAppWinAuthenticationAppPool'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open
database "MyDatabase" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\WebAppAppPool'.
Things I've tried:
I've tried to make the "IIS APPPOOL\WebAppAppPool" user to be the "owner" of the database but no difference but still fails with the same error.
I've deleted the AppPool user and recreated it but same error.
I've created a another asp.net MVC web app but this time using "user authentication" instead of "Windows Authentication", associated the same app pool to the website, created a new database (i.e. MyDatabase0), assigned "IIS APPPOOL\WebAppAppPool" to it and granted db_datareader and db_datawriter and this worked as immediately. All the membership tables were created successfully.
I've checked the 'identity.Name' and it is set to the username I've logged in as for the website i.e. MyMachine\Me and the Identity.AuthenticationType is set to negotiate. The impersonationLevel is set to 'impersonate'
I've tried changing the 'Identity' under the 'Process Model' in 'IIS' to LocalSystem, LocalNetwork and NetworkService instead of using the ApplicationPoolIdentity and it made no difference. All of them generated the same error described above except for the credential name matching whatever the identity was set to.
Can you think of anything else that could be causing this problem? Am I missing something in terms of what needs to be set/done in order for this to work?
Can you even use the AppPool when using Windows Authentication?
Thanks