Click here to Skip to main content
15,884,077 members
Articles / Hosted Services / Azure

Connection Strings in Azure Application Configuration Services

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
18 Nov 2016CPOL2 min read 7.2K   1   2
Connection Strings in Azure Application Configuration Services

Some days ago, I spent some hours trying to solve a problem with this site regarding “connection strings” on production environment.

Here is an excerpt from my web.config file. It lacks the complete information for security reasons but it doesn’t matter to set out the issue.

image

I didn’t have any problem on local environment connecting to the same “Azure Sql DataBase” by means of a connection string called “defaultConnection”. You’ll see later on that this name is very important to understand the issue. I almost went crazy changing the connection string directly in “web.config” file on production without success. So, I didn’t understand absolutely nothing about the reason of this problem. Even I was thinking about a possible problem in Azure, but…I was wrong Sorpresa

Looking for similar problems on the internet, I discovered that Azure has a functionality to substitute the connection string on production if the key name given to the connection string matches the name given to the connection string in your “web.config” application file. Besides, Azure creates by default a connection string called “defaultConnection” when you are creating a new SQL Azure database for the first time. Thus, someone might already guess which was the reason for all my problems…

I had created a SQL Azure Database some weeks ago in another server and without diving a lot into it, the fact is that there was a wrong content in the “Connection Strings” section in “Azure Application Configuration Service”, in particular with a ”defaultConnection” key name. So, the content from my “web.config” file inside the “defaultConnection” key was always replaced by the wrong content saved in “Azure Application Configuration Service and consequently originating the mistake and my related headaches.

To solve the problem, I just had to replace the connection string in “Azure Application Configuration Service” with the correct one. You can see it (in Spanish) in the image below:

Azure Application Configuration Service

I suppose you already know it but if not, you can obtain the correct connection strings in Azure from “SQL Database Configuration Tool”:

SQL Database Configuration Tool

By clicking on “Show Connection Strings” or “Mostrar Cadenas de Conexión”, you gain access to the following option:

Sql Azure Connection String

And finally, you just have to copy and paste.

Once setting out the problem and having understood well how it works, I have to say that this option is great to avoid changing your connections strings whenever you have to publish your site on production environments.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Spain Spain
Telecommunication Engineer by University of Zaragoza, Spain.

Passionate Software Architect, MCPD, MCAD, MCP. Over 10 years on the way building software.

Mountain Lover, Popular Runner, 3km 8'46, 10km 31'29, Half Marathon 1h08'50, Marathon 2h27'02. I wish I could be able to improve, but It's difficult by now

Comments and Discussions

 
PraiseShare Pin
sosplombierorleans20-Nov-16 9:56
sosplombierorleans20-Nov-16 9:56 
GeneralRe: Share Pin
jamuro7720-Nov-16 11:08
jamuro7720-Nov-16 11:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.