I was trying to host my WCF service on IIS. However, the application was not able to access the database. The error in my catch block was saying “The underlying provider failed on Open.”
Looking at the error I understood, my application was not able to access the database. I verified the connection string and it looked fine. So I checked the Event Viewer, where it showed a different error.
“Login failed for user ‘IIS APPPOOL\DefaultAppPool’. Reason: Token-based server access validation failed with an infrastructure error. Check for previous errors. [CLIENT: <local machine>]”
This error suggests that the DefaultAppPool under which my application was running, was trying to log into the database and it was not getting access.
Hence I went to my AppPool on IIS and changed its identity to NetworkService. Thats it. This resolved the issue for me.
Steps for making this change –
- Go to IIS
- Select the AppPool on which your application is hosted
- Go to Advanced Settings
- In Process Model section locate Identity
- Change the Identity to NetworkService
Hope this helps in resolving your issue too. Happy coding!!