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!
Get connection informationSign in to the Azure portal. Select SQL Databases from the left-hand menu, and select your database on the SQL databases page. Select Connection strings under Settings and copy the complete ADO.NET connection string.
Go to "Platform Features" and select "Networking" - there you will get the option to setup the Hybrid connection for the Azure Function. Show activity on this post. If you are using Linux app service plan, this is impossible. Hybrid connectins just supported by Windows type app services.
Configure connection strings. In the Azure portal, search for and select App Services, and then select your app. In the app's left menu, select Configuration > Application settings. For ASP.NET and ASP.NET Core developers, setting connection strings in App Service are like setting them in <connectionStrings> in Web.
A connection string includes the authorization information required for your application to access data in an Azure Storage account at runtime using Shared Key authorization. You can configure connection strings to: Connect to the Azurite storage emulator.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With