Azure Functions Database Connection String

前端 未结 14 688
谎友^
谎友^ 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:35

    The best way to do this is to add a Connection String from the Azure portal:

    • From your Function App UI, click Function App Settings
    • Settings / Application Settings
    • Add connection strings

    They will then be available using the same logic as if they were in a web.config, e.g.

    var conn = System.Configuration.ConfigurationManager
                     .ConnectionStrings["MyConn"].ConnectionString;
    

    Or if you're using a non-.NET language, you can use App Settings instead, which become simple environment variables at runtime that your functions can access.

提交回复
热议问题