gpt4 book ai didi

entity-framework - 运行 azure 函数和 Entity Framework 时找不到连接字符串

转载 作者:行者123 更新时间:2023-12-03 22:32:05 24 4
gpt4 key购买 nike

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

No connection string named 'YogaBandyDatabase' could be found in the application config file.

我尝试将连接字符串放入 .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>

最佳答案

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

关于entity-framework - 运行 azure 函数和 Entity Framework 时找不到连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47917238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com