asp.net core 2.0 - Value cannot be null. Parameter name: connectionString

后端 未结 22 1890
时光取名叫无心
时光取名叫无心 2020-12-13 10:00

I had the following error in package manager console when Add-Migration

Value cannot be null. Parameter name: connectionString

22条回答
  •  一向
    一向 (楼主)
    2020-12-13 10:01

    I had such issue when load tesing the service (I recommend it to all) and had ~3/1000 requests with errors, so I changed

    services.AddDbContextPool(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    

    to

    string connectionString = Configuration.GetConnectionString("DefaultConnection");
    services.AddDbContextPool(options =>
    options.UseSqlServer(connectionString));
    

    So it reads connections string 1 time and doesn't use Configuration on every request. And now 100% requests are successful. But it seems to be a bug in .Net Core

提交回复
热议问题