Home > database >  Entity Framework Core Add Migration gives Value cannot be null. (Parameter 'connectionString�
Entity Framework Core Add Migration gives Value cannot be null. (Parameter 'connectionString�

Time:01-01

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True"
}

Here please check

builder.Services.AddDbContext<AuthDbContext>(options => options.UseSqlServer(
    builder.Configuration.GetConnectionString("AuthConnectionString")));
builder.Services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<AuthDbContext>();

I was trying to add the migration but don't know why i am getting this error System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString') at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName) at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction) at Program.<>c__DisplayClass0_0.<$>b__0(DbContextOptionsBuilder options) in C:\Users\Seventhball\source\repos\EmployeeLeaveManagement\EmployeeLeaveManagement\Program.cs:line 9

CodePudding user response:

If defined like this:

"AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True"

use this:

builder.Configuration.GetValue<string>("AuthConnectionString")

if you define it like this:

"ConnectionStrings": { "AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True;"}

use this: :

builder.Configuration.GetConnectionString("AuthConnectionString")
  • Related