[英]While I'm working ins asp.net core 3.1 getting this error Value cannot be null. (Parameter 'connectionString')
System.ArgumentNullException: 'Value cannot be null. System.ArgumentNullException: '值不能为空。 (Parameter 'connectionString')
(参数'connectionString')
I am getting this error I think that problem brings from appsetting.json but I can't find it我收到此错误我认为该问题来自 appsetting.json 但我找不到它
"AllowedHosts": "*",
"ConnectionString": {
"EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
}
Error bring from _config.GetConnectionString("EmployeeDbConnection)错误来自 _config.GetConnectionString("EmployeeDbConnection)
public Startup(IConfiguration config)
{
_config = config;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContextPool<AppDbContext>(options => options.UseSqlServer(_config.GetConnectionString("EmployeeDbConnection")));
services.AddScoped<IEmployeeRepository, SqlServerRepository>();
services.AddMvc(options => options.EnableEndpointRouting = false).AddXmlSerializerFormatters();
}
The reason is in your appsettings.json
:原因在您的
appsettings.json
:
Change the code to( ConnectionString
to ConnectionStrings
):将代码更改为(
ConnectionString
到ConnectionStrings
):
"AllowedHosts": "*",
"ConnectionStrings": {
"EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.