Entity Framework Error - The underlying provider failed on Open

September 24, 2013 by Anuraj

.Net ASP.Net MVC Entity Framework

Yesterday while working on an ASP.Net MVC application, I got an error like this from Entity Framework Data Context. The problem started when I deployed the application in IIS server, while in the development server (IIS Express) it was working fine. In the connection string, I was using Windows Authentication.

After looking into the Event Log, I come across a event log like this, under Windows logs > Application

Login failed for user ‘IIS APPPOOL\DefaultAppPool’. Reason: Failed to open the explicitly specified database ‘AlertDB’. [CLIENT: ]

So IIS is trying to access the database under the credential ‘IIS APPPOOL\DefaultAppPool’. I looked that the server security settings via SQL Server Management Studio and, sure enough, that account is not listed as one of the users allowed to connect. And I could find the similar user. Later I found the normal practise is use “NT AUTHORITY\NETWORK SERVICE” user to connect from IIS to SQL Server, instead of the default application pool identity.

You can modify it by selecting the Advanced settings in the Application Pool and under Process Model change the Identity to Network Service from ApplicationPoolIdentity.

IIS - Advanced Settings - Change Process Model Identity

Happy Coding.

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub