Azure Functions Database Connection String

前端 未结 14 679
谎友^
谎友^ 2020-12-05 17:08

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

14条回答
  •  情深已故
    2020-12-05 17:18

    Jan_V almost nailed it, which led me to experiment with this in the local.settings.json

    {
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true;",
        "AzureWebJobsDashboard": ""
      },
      "ConnectionStrings": {
        "MyConnectionString": "[YourConnectionStringHere]"
      }
    }
    

    This allows you to use the ConfigurationManager.ConnectionStrings[] we are all used to.

    var sqlConnection = ConfigurationManager
                       .ConnectionStrings["MyConnectionString"].ConnectionString;
    

提交回复
热议问题