![](/img/trans.png)
[英]Value cannot be null. Parameter name: connectionString when i run add-migration
[英]Value cannot be null. Parameter name: connectionString
因此,我一直在研究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?}");
});
}
这是我在appsettings.json上的连接字符串
{
"ConnectionString": {
"LibraryConnection": "Server(localdb)\\MSSQLLocalDB;Database=Library_Dev;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
请注意,我有一个LibraryData项目(这是另一个项目),并且该类包含一个名为LibraryContext的类。
public class : DbContext
{
public LibraryContext(DbContextOptions options) : base(options) { }
public DbSet<Patron> Patrons { get; set; }
}
根据网上的资料和问题,我已经完成了所有工作,因此我似乎找不到我在做错什么! 有人可以帮我吗?
我认为您在appsettings.json中打了错字ConnectionString应该是ConnectionStrings
{ "ConnectionStrings": { "LibraryConnection": "Server(localdb)\\\\MSSQLLocalDB;Database=Library_Dev;Trusted_Connection=True;MultipleActiveResultSets=true" }, "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Warning" } } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.