❔ How to use the Azure function I built to retrieve the connection string? cant puzzle the pieces.

I have this function:
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

string name = req.Query["name"];
string ENVIROMENT = Environment.GetEnvironmentVariable("ConnectionStrings:Default");

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;

string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $" {ENVIROMENT}";

return new OkObjectResult(responseMessage);
}


}
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

string name = req.Query["name"];
string ENVIROMENT = Environment.GetEnvironmentVariable("ConnectionStrings:Default");

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;

string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $" {ENVIROMENT}";

return new OkObjectResult(responseMessage);
}


}
The connection string is stored in the local.setting.json file in the function project. My question is how do I use this:
.UseSqlServer( configuration.GetConnectionString("Default"));
.UseSqlServer( configuration.GetConnectionString("Default"));
To read it? Do I understand correctly that I can store the access information there? I saw something about creating environment variables in azure and reading it with the function, not sure what's correct. Any advice would be appreciated
3 Replies
Landan
Landan2y ago
https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-aspnet-core-app?tabs=core6x It has code examples on setting up your startup.cs. I dont remember if I used DI in my azure functions so I cant give an azure function example.
Quickstart for Azure App Configuration with ASP.NET Core
Create an ASP.NET Core app with Azure App Configuration to centralize storage and management of application settings for an ASP.NET Core application.
antimatter8189
antimatter8189OP2y ago
Not sure thats what i need
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server