2
votes

I have created azure function app project using azure function tool for vs2015.

https://blogs.msdn.microsoft.com/webdev/2016/12/01/visual-studio-tools-for-azure-functions/

the project has appsettings.json file, which is being used to read application settings, which we set in application settings section on azure function. the format is

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    ------
   }
}

How do i add connection string in this appsettings.json file , which i have configured in azure function Connection string section

2
I have tried following { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "", ------ }, "ConnectionStrings":{ "ConnectionStringName" : "Value" } } I tried to access connecton string by ConfigurationManager.ConnectionStrings["ConnectionStringName"] but no luck...Utkarsh Patel

2 Answers

3
votes

You can just edit the appsettings.json file in a text editor to add the connection string.

{
  "IsEncrypted": false,
   "Values": {
        "AzureWebJobsDashboard": "<connectionstring>",
        "AzureWebJobsStorage": "<connectionstring>",
        "MyAppsetting": "<connectionstring>",
        .... etc ...
    },
    "ConnectionStrings": {
        "DbConStr": "data source=(localdb)\\MS..." ,
        "ConnectionStringName": "data source=(localdb)\\MS..." ,
         .... etc ...
    }
}

The file should be in the root of your project.

2
votes

The latest released version 0.91 of the Azure Functions CLI (which is what is used by the Visual Studio Tooling) doesn't set a the providerName attribute for connection strings (see https://github.com/Azure/azure-functions-cli/issues/46).

The issue has been fixed in the CLI repo, but we haven't released a new version yet. If you want the fix sooner, you can build the project yourself and copy the build output to the folder %USERPROFILE%\AppData\Local\Azure.Functions.Cli\1.0.0-beta.91.