Entity Framework Error - The underlying provider failed on Open

Posted by Anuraj on Tuesday, September 24, 2013

.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.



Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon



Subscribe


Copyright © 2017 - Anuraj P. 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. Hosted with ❤ by GitHub