Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (45.3k points)

How do I add or access an app.config file in Azure functions to add a database connection string?

If you're not supposed to add an app.config and there is a better way to access an external database to execute the function please let me know best practices. Thanks!

1 Answer

0 votes
by (16.8k points)

Try this with the local.settings.json

{

  "IsEncrypted": false,

  "Values": {

    "AzureWebJobsStorage": "UseDevelopmentStorage=true;",

    "AzureWebJobsDashboard": ""

  },

  "ConnectionStrings": {

    "MyConnectionString": "[YourConnectionStringHere]"

  }

This allow you to use ConfigurationManager.ConnectionStrings[]

var sqlConnection = ConfigurationManager

                  .ConnectionStrings["MyConnectionString"].ConnectionString;

Browse Categories

...