Search code examples
azureazure-functions

how to fix the broken connection string in local.settings.json file on azure function app?


This is the content inside local.settings.json file. here the password have special characterslike (=,%) which i suspect is the issue.

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "python",
        "SQLConnectionString": "Server=tcp:test.database.windows.net,1433;Database=<>;User Id=testuser;Password="
    }
}

I have a sql trigger in the main function_app.py file. Also, is there any way i can not hardcode these values .

I have tried using urllib.parse to encode the password for use. I've configured an Azure Key Vault, and a function generates this connection string but couldn't use it . How do I pass it in here?"


Solution

  • I have a sql trigger in the main function_app.py file. Also, is there any way i can not hardcode these values . I've configured an Azure Key Vault, and a function generates this connection string but couldn't use it . How do I pass it in here?"

    You can store it in Environment variables Section as below:

    enter image description here

    Or you can store it in Key Vault and bring it to function app by pulling the reference and storing it as

    @Microsoft.KeyVault(VaultName=keyvaultname;SecretName=keyname) and then pull the reference:

    enter image description here

    For further information on connection between keyvault and function app refer SO-Thread1 and SO-Thread2.

    Or you can also use App configuration service and get it to function app using @Microsoft.AppConfiguration(Endpoint=https://rithwik98.azconfig.io; Key=test)

    If you do not want to give password, you can use managed identity or client credentials and give the role to it in sql server to access from function app