【发布时间】:2017-05-22 09:44:33
【问题描述】:
信息
我的解决方案中有多个项目,其中一个是 DAL,另一个是 ASP.NET MVC6 项目。
由于 MVC6 项目也是启动项目,我需要在此处添加我的连接字符串。
我看到this solution,但是不接受,也不行。
我的尝试
appsettings.json
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=.\\SQLEXPRESS;Database=Bar;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"FooBar": {
"ConnectionString": "Server=.\\SQLEXPRESS;Database=Bar;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]))
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:FooBar:ConnectionString"]));
}
然而,当我尝试使用FooBar 连接字符串访问数据时,我收到以下消息:
"附加信息:没有名为 'FooBar' 的连接字符串 在应用程序配置文件中找到。”
问题
如何让多个连接字符串正常工作?
【问题讨论】:
标签: c# json asp.net-core asp.net-core-mvc connection-string