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

前端 未结 14 1848
南旧
南旧 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:59

    this is was the message that appeared me

    Value cannot be null. Parameter name: connectionString

    I fix it changed in the startup these lines

    services.AddDbContext<AppIdentityDbContext>(options =>
    options.UseSqlServer(
    Configuration["Data:BookStoreContext:ConnectionString"]));
    

    To

    services.AddDbContext<AppIdentityDbContext>(options =>
    options.UseSqlServer(
    Configuration.GetConnectionString("BookStoreContext")));
    
    0 讨论(0)
  • 2020-12-16 11:00

    Maybe you can try this:

    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer("DefaultConnection")
    );
    

    Then set your appsettings.json do something like this:

    "ConnectionStrings:": {
        "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=HOME1_DATABASE;Trusted_Connection=True;MultipleActiveResultSets=true"
    },
    

    After that, when a I add migration via the console, it succeeds.

    0 讨论(0)
提交回复
热议问题