This problem occurred when the connection string could not be found.
You probably have the following codes in the Startup class:
public void ConfigureServices(IServiceCollection services) { services.AddDbContext<BenchmarkContext>(options => options.UseSqlServer(Configuration.GetConnectionString("yourConnectionString name from appsettings.json"))); }
These methods solve your problem :
1- Instead of Configuration.GetConnectionString("yourConnectionString name from appsettings.json") just enter the connection string.
public void ConfigureServices(IServiceCollection services) { services.AddDbContext<BenchmarkContext>(options => options.UseSqlServer("Data Source=.;Initial Catalog=Benchmark;Persist Security Info=True;User ID=****;Password=****")); }
2- If you intend to use the configuration file, add these codes to the Startup class:
public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration; public void ConfigureServices(IServiceCollection services) { services.AddDbContext<BenchmarkContext>(options => options.UseSqlServer(Configuration.GetConnectionString("TestConnection"))); }
Apps.txt file:
{ "ConnectionStrings": { "TestConnection": "Data Source=.;Initial Catalog=Benchmark;Persist Security Info=True;User ID=****;Password=****" } }
After that, run the add-redirect name command in the package manager console
source share