os2499
os2499

Reputation: 43

Database connection string with Azure Keyvault in Azure Function local.setting.json in .NET Core

I am supporting an Azure Function someone wrote in C# in .NET Core 2.2.4. The function app is connecting to a database using a SQL Server account, and username and password are hardcoded in the connection string at the moment. We want to use Azure Keyvault now so that we don't have the password in the connection string.

Here is the connection with hardcode username and password in local.setting.json file:

"SQLConnectionString":"Server=tcp:xxxx-sql.database.windows.net,1433;Initial Catalog=abc-db;Persist Security Info=False;User ID=xxxx;Password=xxxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

Upvotes: 0

Views: 1242

Answers (1)

RithwikBojja
RithwikBojja

Reputation: 11363

If your Username and Password are in KeyVault Secrets then You should give access to use the secrets as below reference:

enter image description here

enter image description here

enter image description here

In configuration section Of function app Click on Add Application Setting and Then type password and then below code

@Microsoft.KeyVault(SecretUri=https://mykeyvaultname.vault.azure.net/secrets/mysecretname/)

enter image description here

Then codes for using inside Azure Function are reference1 and reference2.

Upvotes: 0

Related Questions