It took us a long time and a bit of luck to get to the bottom of this problem. It turns out that at two completely different client sites they had computers whose machine.config file had been affected in a way that was causing an error in Code First.
The error that was being thrown at runtime was:
“Unable to determine the provider name for connection of type 'System.Data.SqlClient.SqlConnection'”
Yet the database was reachable from ADO.NET code in the app that used the same connection string.
This led us down a lot of exploration of the provider settings in the web.config file.
Finally a clever developer at the client site wrote a little debugging tool that helped us see the *true* error which helped him get to the bottom of the problem.
The real error was:
"'DbProviderFactories' section can only appear once per config file error'"
And it turned out that the machine.config had extra DbProviderFactories sections in it’s system.data element.
We are still trying to figure out what may have created this problem in machine.config but in the meantime, I’m trying to create some searchable text to help the next person who hits this problem.
I’ve ensured that the EF team is already aware of the problem.
Here is the MSDN forum thread related to this problem along with the solution: