Azure Functions: CosmosDBTrigger connection string storage - azure

I asked yesterday where to store the connection string for a CosmosDBTrigger. It worked great until I had to push it up to Azure. Now the function isn't working at all. It works locally just fine though. There is no difference between codebases so the only thing I can think of is the connection string isn't be pulled from local.settings.json when on Azure. I mean, it wouldn't surprise me if that was the case since the file has the word local in it.
I tried putting the contents in the host.json, but that didn't work either.
How do you specify the connection string when your Function is running on Azure?

local.settings.json is not used in Azure. Instead, settings are taken from App Service Settings.
For your yesterday's example, go to Function App's Application settings tab and add a value with key DbConnString there.
If you are using func CLI, you can publish settings from local.settings.json file to Azure Application settings by running
func azure functionapp public <App> --publish-local-settings

You need to put it in the Application Settings for the function app. These can be setup using the Azure Portal or deployed as part of the ARM template I believe.
Azure Application Settings

Related

How to upload SignalRConnectionString stored in local.settings.json in VS to Azure functions on azure portal

I was able to deploy Azure Functions to run SignalR Messaging to the Azure portal, but the local.settings.json file which contained the SignalRConnectionString required to run SignalR Messaging was not uploaded. How can I add this string on the Azure portal?
Error message on Azure portal :
Microsoft.Azure.WebJobs.Extensions.SignalRService: The SignalR Service connection string must be set either via an 'AzureSignalRConnectionString' app setting, via an 'AzureSignalRConnectionString' environment variable, or directly in code via SignalROptions.ConnectionString or SignalRAttribute.ConnectionStringSetting.
the local.settings.json file which contained the SignalRConnectionString required to run SignalR Messaging was not uploaded. How can I add this string on the Azure portal?
Please check whether you add all Function app settings that you defined in the local.settings.json to function app in Azure when you publish the project.
If you did not add AzureSignalRConnectionString for the Remote field, you can select and navigate to your function app on Azure portal, then you can update value of AzureSignalRConnectionString or add new application setting for your function app in Configuration under Platform features blade, like below.
Application settings
Test Result

Azure cloud service cannot read from web project's web.config

The config value is stored in the Web.config. When I build the web project, the Web.config gets copied to the build folder as {ProjectName}.dll.config. Running the web app locally works fine, the config value gets read without problem using ConfigurationManager.AppSettings["{key}"];.
When I build the cloud service however, the {ProjectName}.dll.config does not get copied to the cspkg file that I upload and run on Azure. I would expect it to be in approot/bin. However there is a Web.config in approot.
Running on Azure the app fails when trying to read from the app settings using ConfigurationManager.AppSettings["{key}"];.
I am aware of CloudConfigurationManager but I would like to avoid having to maintain the configuration in both, Web.config and the cloud cscfg.
The service configuration file specifies the number of role instances to deploy for each role in the service, the values of any configuration settings, and the thumbprints for any certificates associated with a role.
In Solution Explorer, select Properties>Development>Service Configuration and set the value as Cloud.
Then, set the web role's Service Configuration as Cloud.
In setting tab, Add Setting about connection string and what you want to store.
The following code illustrates an example of how to access a connection string. Replace the placeholder with the appropriate value.
// Setup the connection to Azure Storage
var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("<ConnectionStringName>"));
For more details about how to configure Azure Cloud service roles with Visual Studio, you could refer to this article.

Azure Functions - Visual Studio Tools

I was trying to create Azure Functions as provided in the help link - https://blogs.msdn.microsoft.com/webdev/2016/12/01/visual-studio-tools-for-azure-functions/
I am actually creating a Evenhub trigger to write the messages to blob storage.
When I try to run the project, I am getting an error:
"Microsoft.Azure.WebJobs.Host: Error indexing method
'Functions.DashPOCEventHub'. Microsoft.WindowsAzure.Storage: Value
cannot be null."
I have put the correct values in the appsettings.json.
Can somebody help me with this error?
Also, when I try to publish the function to Azure, the appsettings.json is not being set correctly. I cannot see the values and keys when I go into the Azure UI application settings page.
appsettings.json won't create/override your web app ApplicationSettings when you deploy. You'll need to specify the ApplicationSettings for the web app explicitly.
The reason for this is so that you can use different secrets locally (appsettings.json) from what you deploy (web app appsettings).
There is more info on appsettings.json and web app Application Settings here.
Silly John, did you update the Azure CLI when you run your Function Locally? Today is on the Azure Functions Console CLI 1.0.0-beta.97.
Probably, this update solves this issue.

Connection strings set in Azure portal not being picked up by application

I have a webapp deployed to an Azure Web App. In the webapp I am using MembershipReboot, with Entity Framework. The Sql Server database is also in Azure.
It is deployed via BitBucket integration and continuous deployment, in a staging slot.
As part of the build process, a web.config transfrom, changes the connection string value to "dummy".
I set this the connection string, named MembershipReboot, in the Azure portal.
When I browse to the application, I get this error:
Format of the initialization string does not conform to specification starting at index 0.
If I change the connection string in the web.config, to be the Sql Azure connection string the app loads fine. If I set it back to "dummy" then I get the above error.
This indicates to me that the connection string set in the Azure portal isn't being picked up by the application.
I created this Azure enviromnent using the ARM template deploy, mixed with some Azure powershell commands. I've tried creating the environment by hand too, with the same issue.
Any ideas on what to look at next?
edit: Just to say, the correct connection string is viewable within Kudu.
Managed to fix this.
It was due to StructureMap being invoked, and creating a database context (via global.asax), before the environment was providing the correct connection string.
In our case, the app was mixing Owin startup and global.asax Application_Start, we had to move the global.asax startup into the Owin startup, and not allow the database context to be created during that startup. I suspect we could have just done the latter.

Windows Azure web.config changed

Recently I had a problem with a service in Windows Azure, I've deploy the app to staging with a connection string to test DB, before I swap to production, i've change the connection string to production DB, that was on saturday, but today at my production environment the connections strings were to test DB.
Is there an schedule to recycle the instances in windows Azure?
If there is, Where did azure took the package to create the new instance?
Thanks in advance.
Azure can recycle your cloud service (Web and Worker) roles at any time and you don't have any control on that. When you deploy your service, it is stored in Azure storage and instances are created from that. Once deployed, you can't change the Web.config file because if redeployed, the new instance will use the original settings stored in your deployment package. It is best practice to store connection strings in the service configuration file instead of the Web.config file since you can change it at runtime.
Check this SO Q/A for the how to: Set the application ConnectionString in the Service Configuration instead of web.config in Azure

Resources