无法找到运行azure函数和实体框架的连接字符串

问题描述 投票:2回答:1

我在一个项目中有一个Asp.Net MVC应用程序,我将用于连接到Entity Framework的数据库上下文文件移动到它自己的项目中,这样我就可以从我的Asp.Net MVC应用程序和我的Azure功能应用程序访问EF 。但是,在尝试获取连接字符串时,运行Azure Function会引发异常。

在应用程序配置文件中找不到名为“YogaBandyDatabase”的连接字符串。

我尝试将连接字符串放入.DataLayer项目的app.config文件中,我尝试将连接字符串放入local.settings.json文件中,我尝试将连接字符串放入应用程序设置连接字符串下的门户网站但是我我仍然得到这个例外。

问题 - 它在哪里寻找连接字符串,它说应用程序配置文件?哪一个?来自.DataLayer项目的那个?我把它正确地放到app.config文件中了吗?

这是我的项目结构

enter image description here

这是上下文文件中的错误

enter image description here

这是.DataLayer项目中的上下文文件

namespace YogaBandy2017.Context
{
public class YogabandyContext : IdentityDbContext<ApplicationUser>
{
    public YogabandyContext() 
        : base("name=YogaBandyDatabase")
    {

    }

    public YogabandyContext(string connectionString)
        : base(connectionString)
    {

    }

    public static YogabandyContext Create()
    {
        return new YogabandyContext();
    }

    public DbSet<YogaBandyError> YogaBandyErrors { get; set; }
    public DbSet<YogaProfile> YogaProfiles { get; set; }
    public DbSet<YogaClass> YogaClasses { get; set; }
    public DbSet<YogaSpaceEvent> YogaSpaceEvents { get; set; }
    public DbSet<ReportImage> ReportImages { get; set; }

    public DbSet<ReportProfile> ReportProfiles { get; set; }

    public DbSet<ReportSpace> ReportSpaces { get; set; }
    public DbSet<YogaSpace> YogaSpaces { get; set; }

    public DbSet<YogaSpaceFollower> YogaSpaceFollower { get; set; }

    public DbSet<YogaProfileFollower> YogaProfileFollower { get; set; }

    public DbSet<RegisteredStudent> RegisteredStudents { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        //modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        base.OnModelCreating(modelBuilder);
    }
}
}

这是带有连接字符串的local.settings.json文件(可能语法不正确)

{
 "IsEncrypted": false,
  "Values": {
   "AzureWebJobsStorage": "the string",
   "AzureWebJobsDashboard": "",
   "yogabandy2017_RootManageSharedAccessKey_SERVICEBUS": "the string"
 },
 "ConnectionStrings": {
   "YogaBandyDatabase": "the string"
 }
}

这是.DataLayer项目的app.config文件中的连接字符串

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <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="YogaBandyDatabase" connectionString="my string" providerName="System.Data.SqlClient" />
    <add name="YogaBandyErrorDatabase" connectionString="my string" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
entity-framework azure connection-string azure-functions
1个回答
-1
投票

这个有点棘手。登录Azure门户并导航到您的功能。单击功能的“概述”选项卡上的“应用程序设置”链接。将EF连接字符串放在“连接字符串”部分下。

© www.soinside.com 2019 - 2024. All rights reserved.