System.ArgumentNullException: '值不能为空。(参数'connectionString')
我收到此错误我认为该问题来自 appsetting.json 但我找不到它
"AllowedHosts": "*",
"ConnectionString": {
"EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
}
Run Code Online (Sandbox Code Playgroud)
错误来自 _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();
}
Run Code Online (Sandbox Code Playgroud)