title: No database provider has been configured for this DbContext .NET Core with SQL Server
body: <p>I have been banging my head against a wall with this one and have been googling to no avail.</p>
  
  <p>I have just started a new ASP.NET Core MVC project, I have installed/updated my packages for these two to 2.2.0:</p>
  
  <pre><code>Microsoft.EntityFrameworkCore.SqlServer
  Microsoft.EntityFrameworkCore.Tools
  </code></pre>
  
  <p>I have set the project to expect .NET Core 2.2.0 as well.</p>
  
  <p>I am able to successfully add my table schemas with this command in Package Manager console to scaffold the Database, so I know the connection string is fine/working:</p>
  
  <pre><code>Scaffold-DbContext "SERVER=Server\Instance;DATABASE=Database;UID=user;PWD=password;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables Table1, Table2, Table3
  </code></pre>
  
  <p>The created model file, <code>DatabaseDBContext.cs</code> looks like this:</p>
  
  <pre><code>public partial class DatabaseDBContext : DbContext
  {
      public DatabaseDBContext()
      {
      }
  
      public DatabaseDBContext(DbContextOptions&lt;DatabaseDBContext&gt; options)
          : base(options)
      {
      }
  }
  </code></pre>
  
  <p>This also contains a method that works to retrieve my scaffold data, but isn't considered safe for production use so I commented this out:</p>
  
  <pre><code>protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  {
      if (!optionsBuilder.IsConfigured)
      {
          optionsBuilder.UseSqlServer("SERVER=Server\\Instance;DATABASE=Database;UID=user;PWD=password;");
      }
  }
  </code></pre>
  
  <p>I added this same connection string to the <code>appsettings.json</code> file:</p>
  
  <pre><code>{
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "ConnectionStrings": {
      "DBConnString": "SERVER=Server\\Instance;DATABASE=Database;UID=user;PWD=password;"
    }
  }
  </code></pre>
  
  <p>I then added the <code>DbContext</code> to the <code>startup.cs</code> file:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      // Add framework services.
      services.AddMvc();
  
      services.AddDbContext&lt;DatabaseDBContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("DBConnString")));
  }
  </code></pre>
  
  <p>Trying to add a new scaffolded controller for one of the tables throws this error:</p>
  
  <blockquote>
    <p>Finding the generator 'controller'...<br>
    Running the generator 'controller'...<br>
    Attempting to compile the application in memory.<br>
    Attempting to figure out the EntityFramework metadata for the model and DbContext: 'TableName'  </p>
    
    <p>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>
    
    <p>StackTrace:<br>
    at Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)<br>
    at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()<br>
    at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure<code>1 accessor)<br>
    at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func</code>1 factory)  </p>
    
    <p>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>
  
  <p>Has anyone got any clue what I am doing wrong here?</p>