title: InvalidOperationException: No database provider has been configured for this DbContext
body: <pre><code>context = new ApplicationDbContext();
  context.Clients.Add(item);
  </code></pre>
  
  <blockquote>
    <p>InvalidOperationException: No database provider has been configured
    for this DbContext. A provider can be configured by overriding the
    DbContext.OnConfiguring method or by using AddDbContext on the
    application service provider. 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.</p>
  </blockquote>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
      {
          public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)
              : base(options)
          {
  
          }
  
          public ApplicationDbContext()
          {
  
          }
  
          protected override void OnModelCreating(ModelBuilder builder)
          {
              base.OnModelCreating(builder);
  
          }
  
          public DbSet&lt;Client&gt; Clients { get; set; }
  </code></pre>
  
  <p>Startup</p>
  
  <pre><code>public class Startup
      {
          public Startup(IHostingEnvironment env)
          {
              var builder = new ConfigurationBuilder()
                  .SetBasePath(env.ContentRootPath)
                  .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  
              if (env.IsDevelopment())
              {
                  // For more details on using the user secret store see https://go.microsoft.com/fwlink/?LinkID=532709
                  builder.AddUserSecrets&lt;Startup&gt;();
              }
  
              builder.AddEnvironmentVariables();
              Configuration = builder.Build();
          }
  
          public IConfigurationRoot Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              // Add framework services.
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                  options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
              services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;()
                  .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
                  .AddDefaultTokenProviders();
  
              services.AddMvc();
  
              // Add application services.
              services.AddTransient&lt;IEmailSender, AuthMessageSender&gt;();
              services.AddTransient&lt;ISmsSender, AuthMessageSender&gt;();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
          {
              loggerFactory.AddConsole(Configuration.GetSection("Logging"));
              loggerFactory.AddDebug();
  
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
                  app.UseDatabaseErrorPage();
                  app.UseBrowserLink();
              }
              else
              {
                  app.UseExceptionHandler("/Home/Error");
              }
  
              app.UseStaticFiles();
  
              app.UseIdentity();
  
              // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715
  
              app.UseMvc(routes =&gt;
              {
                  routes.MapRoute(
                      name: "default",
                      template: "{controller=Home}/{action=Index}/{id?}");
              });
          }
      }
  </code></pre>
  
  <p><strong>Updated</strong> </p>
  
  <p>I added </p>
  
  <pre><code>// Startup.ConfigureServices
  public void ConfigureServices(IServiceCollection services)
      {
          // Add framework services.
          services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
              options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
          //////my=&gt;
          services.AddDbContext&lt;DbContext&gt;(config =&gt;
          {
              config.UseSqlServer(Configuration.GetConnectionString("Default"));
          });
  </code></pre>
  
  <p>and configure it in your appsettings.json</p>
  
  <pre><code>    {
    "ConnectionStrings": {
      "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplicationCore-42a4ac05-477c-4ea7-b286-87423170b48a;Trusted_Connection=True;MultipleActiveResultSets=true",
      "Default": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplicationCore-42a4ac05-477c-4ea7-b286-87423170b48a;"
    },
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Warning"
      }
    }
  }
  </code></pre>
  
  <p>I clicked on the appsettings.json file and change the properties in the property window to "Build Action: Content" and "CopyToOutputDirectory: Copy Always"</p>
  
  <pre><code>&lt;ItemGroup&gt;
    &lt;Content Update="appsettings.json"&gt;
      &lt;CopyToOutputDirectory&gt;Always&lt;/CopyToOutputDirectory&gt;
    &lt;/Content&gt;
  &lt;/ItemGroup&gt;
  </code></pre>
  
  <p>Error not fixed</p>
  
  <p>New error:</p>
  
  <pre><code>var result = await _userManager.CreateAsync(user, model.Password);
  </code></pre>
  
  <blockquote>
    <p>An unhandled exception occurred while processing the request.
    SqlException: A network-related or instance-specific error occurred
    while establishing a connection to SQL Server. The server was not
    found or was not accessible. Verify that the instance name is correct
    and that SQL Server is configured to allow remote connections.
    (provider: SQL Network Interfaces, error: 50 - Local Database Runtime
    error occurred. Во время запуска экземпляра LocalDB произошла ошибка:
    ошибка запуска процесса SQL Server. )</p>
    
    <p>System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
    identity, SqlConnectionString connectionOptions, object providerInfo,
    bool redirectedUserInstance, SqlConnectionString
    userConnectionOptions, SessionData reconnectSessionData, bool
    applyTransientFaultHandling)</p>
  </blockquote>