从ASP.NET MVC中的数据库错误中获取提供程序信息时发生错误

时间:2021-05-06 15:41:52

so, I was trying to follow the tutorial of MVC from here. When I'm in Set up and Execute a Code First Migration part and enter enable-migrations -contexttypename SchoolContext on Package Manager Console, I got this error :

所以,我试图从这里开始遵循MVC的教程。当我在设置并执行代码优先迁移部分并在包管理器控制台上输入enable-migrations -contexttypename SchoolContext时,出现此错误:

An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

从数据库获取提供程序信息时发生错误。这可能是由实体框架使用不正确的连接字符串引起的。检查内部异常以获取详细信息,并确保连接字符串正确。

So, what really happen with this error? I'm new in MVC, I'm just started to learn MVC.

那么,这个错误到底发生了什么?我是MVC的新手,我刚开始学习MVC。

Thanks for your attention for this question.

感谢您对此问题的关注。

1 个解决方案

#1


0  

It would be helpful to see the relevant web.config sections.
Here is an example for a local SQL Server Express:

查看相关的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>

#1


0  

It would be helpful to see the relevant web.config sections.
Here is an example for a local SQL Server Express:

查看相关的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>