title: Setting the SQL connection string for ASP.NET Core web app in Azure
body: <p>I have created a new ASP.NET Core web application in Visual Studio 2015. I've also set up an Azure web app to pull in the app from GitHub and run it. This works fine, but I'm having trouble connecting to the database on Azure.</p>
  
  <p>Locally, this works, and it uses <code>config.json</code> and in code <code>Data:DefaultConnection:ConnectionString</code> for the connection string.</p>
  
  <p>How can I leave the code as it is, and have it work in Azure too? I've tried setting the Application Settings in the portal, both the Connection Strings and the App Settings. And using both "SQLCONNSTR_DefaultConnection" and "Data:DefaultConnection:ConnectionString" as the key. </p>
  
  <p>(Setting the App Settings doesn't seem to work by the way. I think the value I provide is too long).</p>
  
  <p>So how can I provide the connection string for my Azure database to my Azure web app (ASP.NET 5), without checking it in in source control?</p>
  
  <p><strong>Update</strong>
  My Startup.cs looks like this (see <a href="https://github.com/petermorlion/RedStar.Invoicing/blob/master/src/RedStar.Invoicing/Startup.cs" rel="noreferrer">the full file on GitHub</a>):</p>
  
  <pre><code>public Startup(IHostingEnvironment env)
  {
      var configuration = new Configuration()
          .AddJsonFile("config.json")
          .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
  
      if (env.IsEnvironment("Development"))
      {
          configuration.AddUserSecrets();
      } 
  
      configuration.AddEnvironmentVariables();
      Configuration = configuration;
  }
  </code></pre>
  
  <p>In the <code>ConfigureServices</code> method, there is also:</p>
  
  <pre><code>services.Configure&lt;AppSettings&gt;(Configuration.GetSubKey("AppSettings"));
  </code></pre>
  
  <p>and, also in the <code>ConfigureServices</code> method:</p>
  
  <pre><code>services.AddEntityFramework()
              .AddSqlServer()
              .AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; 
                     options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]))
              .AddDbContext&lt;InvoicesDbContext&gt;(options =&gt; 
                     options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
  // So this is where I want my app in Azure to use the connection string I
  // provide in the portal
  </code></pre>