title: How can I implement DbContext Connection String in .NET Core?
body: <p>My situation is quite similar to this link or at least my code is similar and I am trying to find a way to apply this same method in .NET Core syntax.</p>
  
  <p><a href="https://stackoverflow.com/questions/4805094/pass-connection-string-to-code-first-dbcontext">Pass connection string to code-first DbContext</a></p>
  
  <p>My specific code is as follows:</p>
  
  <pre><code>public partial class CompanyFormsContext : DbContext
  {
      public CompanyFormsContext()
          : base("name=CompanyFormsContext")
      {
      }
  
      public CompanyFormsContext(string connName)
          : base("name=" + connName)
      {
      }
      ...
  }
  </code></pre>
  
  <p>I get an error saying: </p>
  
  <blockquote>
    <p>Error  CS1503  Argument 1: cannot convert from 'string' to 'Microsoft.EntityFrameworkCore.DbContextOptions'    CompanyForms..NETCoreApp,Version=v1.0</p>
  </blockquote>
  
  <p>when I go over the parenthesis in <code>base("name=CompanyFormsContext")</code> or <code>base("name=" = connName)</code>. </p>
  
  <p>What is the correct way of implementing this functionality in .NET Core?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I wanted to share that I have the following information for database connection in my appsettings.json file: (However, I do not have settings in the startup.cs)</p>
  
  <pre><code>  "Data": {
      "CompanyFormsContext": {
        "ConnectionString": "Server=(localdb)\\projectsv13;Database=companyforms;Trusted_Connection=True;"
      },
      "CompanyFormsContextQA": {
        "ConnectionString": "Server=(localdb)\\projectsv13;Database=companyforms;Trusted_Connection=True;"
      }
    }
  </code></pre>
  
  <p>and I have found the following link <a href="https://stackoverflow.com/questions/29945317/adding-dbcontextoptions-in-startup-cs-not-registering-data-store">Adding DbContextOptions in Startup.cs not registering data store</a> in the website and I am wondering if a simple <code>protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)</code> will be enough to fix my connection or not?</p>
  
  <p>From the link: </p>
  
  <pre><code>services.AddEntityFramework(Configuration)
      .AddSqlServer()
      .AddDbContext&lt;MyDbContext&gt;(
          options =&gt;
          options.UseSqlServer(Configuration.Get("Data:CompanyFormsContext:ConnectionString"))
      );
  </code></pre>
  
  <p>Do I need this kind of a service in my Startup.cs?</p>