Database connection counter inside appsettings.json file

122 Views Asked by At

InvalidOperationException: Unable to resolve service for type 'Context.dbcontext' while attempting to activate 'Api.Controllers.ReportsController'.

enter image description here

1

There are 1 best solutions below

0
Chen On

In .net6:

Add this line to Program.cs:

builder.Services.AddDbContext<dbcontext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("connectionstring")));

In .net5 or others:

Add this line to Startup.cs:

services.AddDbContext<dbcontext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("connectionstring")));

For more details,you can refer to this document.