Value cannot be null. Parameter name: connectionString appsettings.json in starter

前端 未结 14 1884
南旧
南旧 2020-12-16 10:07

I am trying to write my connection string in my appsettings.json file and bring it into my startup file but I keep getting a Value cannot be null. Parameter name: connection

14条回答
  •  死守一世寂寞
    2020-12-16 10:51

    You need to change your appsetting.jsonto:

        {
      "Data": {
        "ConnectionStrings": {
          "DefaultConnection": "Data Source=server;Initial Catalog=dbase;Trusted_Connection=True;MultipleActiveResultSets=true"
    
        },
        "Logging": {
          "IncludeScopes": false,
          "LogLevel": {
            "Default": "Debug",
            "System": "Information",
            "Microsoft": "Information"
          }
        }
      }
    }
    

    And now will be working:

      var connStr = Configuration.GetConnectionString("DefaultConnection");
    

提交回复
热议问题