I have an Azure Function and a PostreSQL DB in Azure Cloud.
From my Azure Function I want to access the Connection String, let's call it IT-PostgreSQL.
This is my Azure Function:
namespace InjectClaimsTokenFunc
{
public class InjectClaims
{
private readonly ILogger<InjectClaims> _logger;
private readonly DataContext _context;
public InjectClaims(ILogger<InjectClaims> logger, DataContext context)
{
_logger = logger;
_context = context;
}
[Function("InjectClaimsFunc")]
public async Task<IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
{
string username = Environment.GetEnvironmentVariable("BASIC_AUTH_USERNAME", EnvironmentVariableTarget.Process);
_logger.LogInformation($"Username: {username}");
string password = Environment.GetEnvironmentVariable("BASIC_AUTH_PASSWORD", EnvironmentVariableTarget.Process);
_logger.LogInformation($"Password: {password}");
var connectionString = Environment.GetEnvironmentVariable("CUSTOMCONNSTR_IT-PostgreSQL") ?? "Not found";
_logger.LogInformation($"ConnectionString: {connectionString}");
}
}
}
I can retrieve get the BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD from the Application Settings.
I always get "Not found" for the connection string now matter how I try to retrieve it. How can I retrieve the connection string from Connection strings? The connection string has a value set in Azure.
