EF Code First(Azure)-访问数据库时出错



直到最近,我的解决方案只有一个web项目。它已部署到Azure。

然后就需要WebJobs,它应该共享数据层,所以我将任何EntityFramework代码(Configuration/IdentityModels)提取到他们自己的项目中。

现在,当我尝试使用命令行"添加迁移"时,我会得到以下错误:

访问数据库时出错。这通常意味着与数据库的连接失败。检查连接字符串是否正确,并且正在使用适当的DbContext构造函数以指定它或在应用程序的配置文件中找到它。看见http://go.microsoft.com/fwlink/?LinkId=386386有关的信息DbContext和连接。有关的详细信息,请参阅内部异常失败

以下是EF项目的App.Config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <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>
    <connectionStrings>
      <add name="Default" connectionString="Data Source=.SQLEXPRESS;Initial Catalog=Sample;Integrated Security=True;Connect timeout=15;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

有人能帮忙吗?

我刚刚遇到了同样的问题。

似乎存在配置子元素的必需顺序。

就我而言,我将它们改为:

<configSections>...</configSections>
<startup>...</startup>
<system.data>...</system.data>
<connectionStrings>...</connectionStrings>
<entityFramework>...</entityFramework>

最新更新