Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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;

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...