title: Access asp net core application connection string from another project
body: <p>I have a ASP NET CORE project, where I have a connection string and my dbcontext is in a .net 4.52 class library project. I would like to know how to access the connection string from the asp net core project.</p>
  
  <p>asp net core - appsettings.json:</p>
  
  <pre><code>"ConnectionStrings": {        
      "MyConnectionString": "Data Source=.\\mydb;Initial Catalog=mydb;User Id=myuser;Password=mypassword; MultipleActiveResultSets=true"
  }, ...
  </code></pre>
  
  <p>My <code>dbContext</code>: </p>
  
  <pre><code>public MyContext() : base("name=MyConnectionString")
  {
      Database.SetInitializer(new MigrateDatabaseToLatestVersion&lt;MyContext, Migrations.Configuration&gt;());
  }
  
  public MyContext(string connString) : base(connString)
  {
      Database.SetInitializer(new MigrateDatabaseToLatestVersion&lt;MyContext, Migrations.Configuration&gt;());
  }
  </code></pre>
  
  <p>When I run the app I get the error: no connection string named <code>MyConnectionString</code> could be found in the application config file. Even if I add a connection string section to the asp net core project web.config file.</p>
  
  <p>When I hardcode the connectionstring everything works fine.</p>