7

I have uploaded a azure webjob in a azure web site. I was trying to read a connection string from the azure website where the azure webjob is using below code but it is not returning anything. The connection strings in the azure websites are located in the configure tab of the azure website. Am I doing something wrong here.

CloudConfigurationManager.GetSetting("ConnString")

Thanks

2 Answers 2

7

The CloudConfigurationManager.GetSetting("ConnString") is looking for a setting with the key "ConnString" in your App Settings within Azure rather than your Connection Strings.

You need to add a value in the App Settings for your Web Site which contains your connection strings

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I changed it to ConfigurationManager.ConnectionString["ConnString"] and this got me the value also. Thanks for the quick answer .
User505210 - You should post that as an answer and I'd upvote it :)
0

To get app settings or connection string use the regular .NET API

System.Configuration.ConfigurationManager.AppSettings["name"] and System.Configuration.ConfigurationManager.ConnectionStrings["name"]

CloudConfigurationManager is for web roles/worker roles.

4 Comments

The CloudConfigurationManager.GetSetting is used as an abstraction, running on azure it will get the azure app settings, running local will access the web.config
When you're using Azure Websites PAAS solution there is no need for redundant abstractions as you just get the proper behavior from the get go that works both locally, on IIS server and in Azure. also you don't need to reference an extra assembly and there is no connection string support for CloudConfigurationManger.
Absolutely, ConfigurationManager.AppSettings works with both web.config and azure settings, there is no need to use CloudConfigurationManager.GetSetting.
If you deploy using Azure Resource Manager Templates you don't know the connection strings in advance. There it is super useful to have access to the configured connection strings in the webjob.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.