Connection to the database failed. Check that connection string is correct and DbContext constructor

Cause: when you were using IIS, your App Pool user was probably 'ApplicationPoolIdentity'. When connecting to network resources, that will connect as local system (so if in a domain, that would be the domain\computer$ account). Presumably that account does not have access to the SQL DB.

Sort of fix: Your change to IIS Express 'fixed' this, connection was made as current user. Not good if you're planning to ever deploy to IIS though.

Better fix: Change your IIS App Pool user to a true Windows user account, which has access to the SQL DB.

I have just gone through exactly same issue, and can confirm above fixes worked for me.


my main project which contains web.config file (contains connection string) was not set as default project. setting it to default project solved the problem.