Ali*_*Ali 0 asp.net asp.net-core-2.0
因此,我一直在研究stackoverflow并检查与我的问题有关的所有问题,并且所有内容都已签出,但是我仍然遇到相同的错误。
值不能为空。参数名称:connectionString
是我运行添加迁移“初始迁移”时的结果。
这是我在Startup.cs上的代码
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<LibraryContext>(options
=> options.UseSqlServer(Configuration.GetConnectionString("LibraryConnection")));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Run Code Online (Sandbox Code Playgroud)
这是我在appsettings.json上的连接字符串
{
"ConnectionString": {
"LibraryConnection": "Server(localdb)\\MSSQLLocalDB;Database=Library_Dev;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,我有一个LibraryData项目(这是另一个项目),并且该类包含一个名为LibraryContext的类。
public class : DbContext
{
public LibraryContext(DbContextOptions options) : base(options) { }
public DbSet<Patron> Patrons { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
根据网上的资料和问题,我已经完成了所有工作,因此我似乎找不到我在做错什么!有人可以帮我吗?
小智 5
我认为您在appsettings.json中打了错字ConnectionString应该是ConnectionStrings
{
"ConnectionStrings": {
"LibraryConnection": "Server(localdb)\\MSSQLLocalDB;Database=Library_Dev;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3834 次 |
| 最近记录: |