No Database Provider Has Been Configured for This Dbcontext' on Signinmanager.Passwordsigninasync

No database provider has been configured for this DbContext' on SignInManager.PasswordSignInAsync

If AddDbContext is used, then also ensure that your DbContext type
accepts a DbContextOptions object in its constructor and passes it to
the base constructor for DbContext.

The error message says your DbContext(LogManagerContext ) needs a constructor which accepts a DbContextOptions. But I couldn't find such a constructor in your DbContext. So adding the below constructor probably solves your problem.

public LogManagerContext(DbContextOptions options) : base(options)
{
}

Edit for comment

If you don't register IHttpContextAccessor explicitly, use below code:

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); 

No database provider has been configured for this DbContext

The context must be injected. If you new it up yourself, the service registration doesn't come into play at all. Here, you're creating it yourself, and not passing anything into it, so this instance definitely doesn't have a provider configured.

Cannot solve this error, No database provider has been configured for this DbContext

Startup.cs, add ConnectionService.Set

public Startup(IConfiguration configuration)
{
Configuration = configuration;
ConnectionService.Set(configuration);
}

ConnectionService.cs

public static string connstring = "";
public static string Set(IConfiguration config)
{
connstring = config.GetConnectionString("MyConnection");
}

ConfigurationContext.cs

public class ConfigurationContext : DbContext {

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.UseSqlServer(ConnectionService.connstring);
}

}

No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring

You can get this error when there is no way for the DI framework to configure the provider by injecting a DbContextOptions. So you just need to add a constructor that will accept one, or add a parameter for a DbContextOptions to be passed in. For example:

public class XYZContext : DbContext
{
// Add this constructor
public XYZContext (DbContextOptions options) : base(options)
{
}

}

No database provider has been configured for this DbContext in .net 6 preview 7

Well, I was trying to find a solution for a few hours, and just after 40 minutos trying after I posted the question here, I get why it was not working.

Everything in the code is right but, the PackageReference are not.

In Jupyter.Core.Api instead of this

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="5.0.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />

It should be like this

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-preview.7.21378.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-preview7" />

And in Jupyter.Core.Data instead of this

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.7.21378.4" />

It should be like this

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.7.21378.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-preview7" />

That solved my problem.

No database provider has been configured for this DbContext .NET Core with SQL Server

So I fixed but it in a really roundabout way. My new project was originally on an older version of .net core. I had updated the version but there must have been something it didn't like during the update. I created a new project and started it on 2.2.0, then it worked...

The code logic was sound above. Still needed the same packages:

Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools

Startup.cs seems quite different, so maybe if anyone else sees this they could try updating the startup.cs code:

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddDbContext<DatabaseDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DatabaseDBConnString")));

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

Had to add a reference to startup.cs for this:

using Microsoft.EntityFrameworkCore;

That was needed for the AddDbContext method to resolve.

After doing this the scaffolding now works. So it's fixed, but it required me to start over to fix it.

No database provider has been configured for this DbContext. Configuring SQL Lite for Identity

You need to properly configure your database context. If you are using SQLite, then it should looke something like this:

services.AddDbContext<ApplicationDBContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

This will assume that you have a connection string properly defined, e.g. "Data Source=database.db" for SQLite.



Related Topics



Leave a reply



Submit