Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 而我';正在使用asp.net core 3.1的m获取此错误值不能为null。(参数&x27;连接字符串&x27;)_C#_Asp.net Core_Model View Controller - Fatal编程技术网

C# 而我';正在使用asp.net core 3.1的m获取此错误值不能为null。(参数&x27;连接字符串&x27;)

C# 而我';正在使用asp.net core 3.1的m获取此错误值不能为null。(参数&x27;连接字符串&x27;),c#,asp.net-core,model-view-controller,C#,Asp.net Core,Model View Controller,System.ArgumentNullException:'值不能为null。(参数“connectionString”) 我收到了这个错误,我认为这个问题来自appsetting.json,但我找不到它 "AllowedHosts": "*", "ConnectionString": { "EmployeeDbConnection" : "server=(localdb)\\MS

System.ArgumentNullException:'值不能为null。(参数“connectionString”)

我收到了这个错误,我认为这个问题来自appsetting.json,但我找不到它

 "AllowedHosts": "*",
    "ConnectionString": {
        "EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
    }
从_config.GetConnectionString(“EmployeeDbConnection”)引发错误

公共启动(IConfiguration配置)
{
_config=config;
}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
//有关如何配置应用程序的更多信息,请访问https://go.microsoft.com/fwlink/?LinkID=398940
public void配置服务(IServiceCollection服务)
{
services.AddDbContextPool(options=>options.UseSqlServer(_config.GetConnectionString(“EmployeeDbConnection”));
services.addScope();
services.AddMvc(options=>options.EnableEndpointRouting=false);
}

原因在于您的
appsettings.json

将代码更改为(
ConnectionString
更改为
ConnectionString
):


是的,这解决了我的问题。我还错过了appsettings.json中ConnectionString中的s。谢谢
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();
        }
 "AllowedHosts": "*",
   "ConnectionStrings": {
    "EmployeeDbConnection" : "server=(localdb)\\MSSQLLocalDB;database=EmployeeDB;Trusted_Connection=true;"
}