none
C# Azure Function ConnectionString always comes back null RRS feed

  • Question

  • I've created a C# Azure Function. I went into Platform Features -> Application Settings and added a connection string (Service Bus). I selected Service Bus from the dropdown and pasted the connection string for my Service Bus. 

    I am accessing the ConnectionString in the following manner:

        var serviceBusConnectionString = ConfigurationManager.ConnectionStrings["ServiceBusConnectionString"];.ConnectionString;

    Strangely, I get a NullReference exception on this line because the ConfigurationManager connection string is null.

    ```
    2017-05-16T20:19:00.053 Exception while executing function: Functions.TimerTriggerCSharp1. mscorlib: Exception has been thrown by the target of an invocation. f-TimerTriggerCSharp1__-754716416: Object reference not set to an instance of an object.
    ```

    Why would this connection string be returning null? When I hard code the ConnectionString, everything works as expected.
    Wednesday, May 17, 2017 5:35 PM

Answers

  • For some reason, it seems that only some of the connection types are working correctly with ConfigurationManager. E.g. I know that type "Custom" works. So if you change your connection type to "Custom" your code will work. I'll follow up on why some connection types don't appear to be working correctly.

    Mathew Charles [MSFT]


    Wednesday, May 17, 2017 8:28 PM

All replies

  • For some reason, it seems that only some of the connection types are working correctly with ConfigurationManager. E.g. I know that type "Custom" works. So if you change your connection type to "Custom" your code will work. I'll follow up on why some connection types don't appear to be working correctly.

    Mathew Charles [MSFT]


    Wednesday, May 17, 2017 8:28 PM
  • Hi Mathew,

    Am getting the same error when connecting to Azure storage account from my Azure functions App. Can you help me resolve this issue.

    ...................................................................

    Sriramprasanth.S

    Monday, July 31, 2017 9:38 AM
  • This still does not work even with "Custom" provider type.  I am having to use workaround with App Settings/Environment Variables.  Can you please reply when this is fixed?
    Thursday, December 21, 2017 2:24 PM
  • This still does not work even with "Custom" provider type.  I am having to use workaround with App Settings/Environment Variables.  Can you please reply when this is fixed?

    I have the same problem with Table storage

    when I'm using 

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(<Connectiosnstring typed out>);

    in code it works

    I can even log the Connectionstring1 value in code from the portal

    log.Info(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);

    but when I’m trying to read it in code instead of the third line in this Quote

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);

    If fails with an server internal error, a timeout of about 900ms without any good errormessage..


    pla


    Monday, March 5, 2018 5:54 PM
  • @pla, how did you configure ConnectionString1 in your application settings? If you configured it as a regular application setting and not a connection string application setting, then you'll want to use ConfigurationManager.AppSettings["ConnectionString1"].
    Monday, March 5, 2018 7:09 PM
  • @Chris

    I use the "Connectionstring": {} in the local.settings.json and that works just fine when running local but when I create the same Connectionstring in Azure portal connection string application setting it can be read but the function does stall without anything but an timeout as I stated above in this thread.

    Do I have to set it up as an appsetting?? What is the connection string application setting in the portal made for then. I just want it to work and be a nice and clean solution.

    I have always use Connectionstrings in all web or workerroles before without any problems so this is  a bit comfucing since the documentation says it should work.

    The connectionstring itself works if I code it in the function or if I fetch it locally when I use ConfigurationManager.ConnectionStrings from the local.settings.json


    pla

    Monday, March 5, 2018 10:55 PM