【发布时间】:2018-06-03 16:12:02
【问题描述】:
我在一个项目中有一个 Asp.Net MVC 应用程序,我将用于连接到 Entity Framework 的数据库上下文文件移到它自己的项目中,这样我就可以从我的 Asp.Net MVC 应用程序和我的Azure 函数应用。但是在尝试获取连接字符串时运行 Azure Function 会引发异常。
在应用程序配置文件中找不到名为“YogaBandyDatabase”的连接字符串。
我尝试将连接字符串放入 .DataLayer 项目的 app.config 文件中,并尝试将连接字符串放入 local.settings.json 文件中,并尝试将连接字符串放入应用程序设置连接字符串下的门户中但我仍然收到此异常。
问题 - 它在哪里寻找连接字符串,它表示应用程序配置文件?哪一个? .DataLayer 项目中的那个?我是否将其正确放入 app.config 文件中?
这是我的项目结构
这是上下文文件中的错误
这是我在 .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