EntityFramework: The underlying provider failed on Open

2014/11/02

数据库连接字符串使用Integrated Security=True验证,在VS2013中可以运行,但在IIS中会报如下错误

System.Data.Entity.Core.EntityException Message=The underlying provider failed on Open. Source=EntityFramework InnerException: System.Data.SqlClient.SqlException Message=Cannot open database “OctooDb” requested by the login. The login failed. Login failed for user ‘IIS APPPOOL\app’.

解决方法参考

http://stackoverflow.com/questions/2475008/the-underlying-provider-failed-on-open

Looking at your connection string, it looks valid. I found this blog post, the problem here is that they were using Integrated Security. If you are running on IIS, your IIS user needs access to the database. If you are using Entity Framework with Transactions, Entity Framework automatically opens and closes a connection with each database call. So when using transactions, you are attempting to spread a transaction out over multiple connections. This elevates to MSDTC.

这里将连接字符串改为用户验证User ID=sa;Password=123即可。