none
GetConnectionString in AmbientConnectionStringProvider returning null! RRS feed

  • Question

  • Hi,

    I have an Azure Function that gets a connection string using AmbientConnectionStringProvider.Instance.GetConnectionString("MyDb").  This works fine on my dev PC and used to work in Azure too.  However, since a few weeks ago, GetConnectionString has started returning null, even though the connection string still exists and we didn't change anything.

    We're using runtime version=2.0.11776.0.

    Any ideas? 

    Monday, June 4, 2018 10:54 AM

Answers

  • Ignore my previous reply (now deleted) which was somewhat incorrect.

    This API is public and we have sample code for webjobs using it, but we have never really intended for it to be used from Azure Functions (and I don't believe we have any test coverage for this case).  

    The most straightforward workaround would be to access these settings as environment variables. They will have a prefix so you'll need to use something like kudu to get the exact environment variable name including the prefix. For example, I added a sql azure connection string (MY_SQL_CONNECTION) and then went here:

    https://<APPNAME>.scm.azurewebsites.net/Env.cshtml

    And I was able to see it in the environment variables list:

    

    In the future we expect to expose this in a more natural way (through IConfiguration).

    Monday, June 4, 2018 9:07 PM

All replies

  • Ignore my previous reply (now deleted) which was somewhat incorrect.

    This API is public and we have sample code for webjobs using it, but we have never really intended for it to be used from Azure Functions (and I don't believe we have any test coverage for this case).  

    The most straightforward workaround would be to access these settings as environment variables. They will have a prefix so you'll need to use something like kudu to get the exact environment variable name including the prefix. For example, I added a sql azure connection string (MY_SQL_CONNECTION) and then went here:

    https://<APPNAME>.scm.azurewebsites.net/Env.cshtml

    And I was able to see it in the environment variables list:

    

    In the future we expect to expose this in a more natural way (through IConfiguration).

    Monday, June 4, 2018 9:07 PM
  • As an alternative, you should try using an App Setting instead of a Connection String. You'll then be able to access it via a straightforward Environment.GetEnvironmentVariable("FOO").
    Monday, June 4, 2018 9:44 PM