title: Azure Function v2 and connection strings
body: <p>I have the following <code>local.settings.json</code> file:</p>
  
  <pre><code>{
    "IsEncrypted": false,
    "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true",
      "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
      "FUNCTIONS_WORKER_RUNTIME": "dotnet",
  
      "SureMdmApiKey": "xxx",
      "SureMdmApiUrl": "xxx",
      "SureMdmUsername": "xxx",
      "SureMdmPassword": "xxx"
    },
    "ConnectionStrings": {
      "StorageConnectionString": "aaaa",
      "DataContext": "aaaa"
    }
  }
  </code></pre>
  
  <p>then I have the following code in Startup.cs file:</p>
  
  <pre><code>[assembly: FunctionsStartup(typeof(FunctionAppSureMdmSync.Startup))]
  namespace FunctionAppSureMdmSync
  {
      public class Startup : FunctionsStartup
      {
          public override void Configure(IFunctionsHostBuilder builder)
          {
              var services = builder.Services;
  
              services.AddTransient&lt;ISureMdmService&gt;(s =&gt; new SureMdmService(
                  url: System.Environment.GetEnvironmentVariable("SureMdmApiUrl"),
                  username: System.Environment.GetEnvironmentVariable("SureMdmUserName"),
                  password: System.Environment.GetEnvironmentVariable("SureMdmPassword"),
                  apiKey: System.Environment.GetEnvironmentVariable("SureMdmApiKey")
                  ));
  
              var connString = System.Environment.GetEnvironmentVariable("ConnectionStrings:DataContext");
              services.AddDbContext&lt;DataContext&gt;(options =&gt; options
                  .UseSqlServer(connString, x =&gt; x.UseNetTopologySuite()));
  
  
              services.AddTransient&lt;ITabletGroupService, TabletGroupService&gt;();
              services.AddTransient&lt;ITabletService, TabletService&gt;();
          }
  
      }
  }
  </code></pre>
  
  <p>and it works fine on local</p>
  
  <p>But when I publish this function to Azure Portal and go to "Configuration" and add "DataContext" to "Connection Strings":</p>
  
  <p><a href="https://i.stack.imgur.com/eMgpo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eMgpo.jpg" alt="enter image description here"></a></p>
  
  <p>My code does not work:</p>
  
  <pre><code>            var connString = System.Environment.GetEnvironmentVariable("ConnectionStrings:DataContext");
  </code></pre>
  
  <p>How to get connection string? I want that it works both, on local and Portal Azure?</p>