I created an HTTP Trigger function in Azure with the hope of reading data from an Azure SQL database. I configured the connection string in the Connection Strings section of the Function App as shown in the image below
I used the below code to try and read the connection string.
var cnnString = ConfigurationManager.ConnectionStrings["TempleDataContext"].ConnectionString;
On execution i see the below error in the logs.
2018-10-24T18:13:56.385 [Information] Script for function 'donors1' changed. Reloading. 2018-10-24T18:13:56.601 [Information] Compilation succeeded. 2018-10-24T18:13:58.511 [Information] Executing 'Functions.donors1' (Reason='This function was programmatically called via the host APIs.', Id=8b140087-4b50-450e-829c-f7abd9e3a1eb) 2018-10-24T18:13:59.067 [Information] C# HTTP trigger function processed a request. 2018-10-24T18:13:59.245 [Error] Executed 'Functions.donors1' (Failed, Id=8b140087-4b50-450e-829c-f7abd9e3a1eb) Object reference not set to an instance of an object.
I wanted to test what all were coming back on the ConnectionStrings object and changed the code to
var cnnStrings = ConfigurationManager.ConnectionStrings;
foreach(var c in cnnStrings)
{
log.LogInformation(c.ToString());
}
When I check the logs, this is the info I see.
2018-10-24T18:16:53.755 [Information] Script for function 'donors1' changed. Reloading. 2018-10-24T18:16:54.540 [Information] Compilation succeeded. 2018-10-24T18:16:55.917 [Information] Executing 'Functions.donors1' (Reason='This function was programmatically called via the host APIs.', Id=508c49bf-d5e6-4a99-b1db-e1a79545fa91) 2018-10-24T18:16:56.063 [Information] C# HTTP trigger function processed a request. 2018-10-24T18:16:56.070 [Information] data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true 2018-10-24T18:16:56.079 [Information] Executed 'Functions.donors1' (Succeeded, Id=508c49bf-d5e6-4a99-b1db-e1a79545fa91)
I am confused as to where it is getting the ConnectionString information.
Just to test a thoery I also added a few lines to read app settings
var appSettings = ConfigurationManager.AppSettings;
foreach(var a in appSettings)
{
log.LogInformation(a.ToString());
}
It did not show me any information for these lines.
I am writing the Azure Functions directly in the portal using C# Script. Am I missing something? Any help would be greatly appreciated.