【问题标题】:An error occurred while getting provider information from the database error in ASP.NET MVC从 ASP.NET MVC 中的数据库错误获取提供程序信息时出错
【发布时间】:2015-10-01 15:09:38
【问题描述】:
所以,我试图从here 学习 MVC 教程。当我在 Setup and Execute a Code First Migration 部分并在 Package Manager Console 上输入 enable-migrations -contexttypename SchoolContext 时,出现此错误:
从数据库获取提供者信息时出错。这可能是由 Entity Framework 使用不正确的连接字符串引起的。检查内部异常以获取详细信息并确保连接字符串正确。
那么,这个错误到底发生了什么?我是 MVC 新手,刚开始学习 MVC。
感谢您对这个问题的关注。
【问题讨论】:
标签:
asp.net
asp.net-mvc
entity-framework
asp.net-mvc-4
【解决方案1】:
查看相关的 web.config 部分会很有帮助。
以下是本地 SQL Server Express 的示例:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="MyDB" connectionString="Data Source=MyServer;Initial Catalog=DBName;Integrated Security=SSPI;persist security info=True;Asynchronous Processing=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>