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.
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
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 of 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) at the image below:
I suppose you already know it but if not ,you can obtain the correct connection strings in Azure from “SQL Database Configuration Tool”:
By clicking on “Show Connection Strings” or “Mostrar Cadenas de Conexión” you gain access to the following option:
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.
Regards.