Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set an ADO.NET Entity Framework connection string via the Windows Azure (Preview) Management Portal?

In the Windows Azure (Preview) Management Portal you can change the configuration options for web sites (see http://www.windowsazure.com/en-us/manage/services/web-sites/how-to-configure-websites/#howtochangeconfig).

I currently set the connection string for my ADO.NET Entity Framework connection via Web.Release.Config, but I want to set it via the Management Portal, but no matter what I use, I always end up with the following error:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

It does work for regular connection strings, ie without the metadata key defining metadata and mapping information (csdl, ssdl, msl).

Here's what I do:

I go to https://manage.windowsazure.com/#Workspaces/WebsiteExtension/Website/[MY-STAGING-SITE-NAME]/configure

Under "connection strings" I have a key named "ApplicationServices" that looks like this:

Server=tcp:xxxxx.database.windows.net,1433;Database=xxxxx;User ID=xxxxx@xxxxx;Password=xxxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;

This one works.

I have another key for the Entity Framework connection. Let's call that one FooBarContext. It looks like this:

metadata=res:///Models.FooBarContext.csdl|res:///Models.FooBarContext.ssdl|res://*/Models.FooBarContext.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:fooserver.database.windows.net,1433;Database=foobar;User ID=myname@fooserver;Password=xxxxxxxxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"

This one causes the error described above. It is copied from the working value in Web.Release.Config, with the " replaced by a ".

I have tried other variations: with the " untouched, with metadata appended at the end, but to no avail. I have reproduced the problem with a second website.

like image 557
Frank van Eykelen Avatar asked Jan 22 '13 13:01

Frank van Eykelen


People also ask

How do I change the connection string in Entity Framework?

If you want to change the connection string go to the app. config and remove all the connection strings. Now go to the edmx, right click on the designer surface, select Update model from database, choose the connection string from the dropdown, Click next, Add or Refresh (select what you want) and finish.

How do I get Azure SQL Server connection string?

Navigate to the database blade in the Azure portal and, under Settings, select Connection strings. Review the complete ADO.NET connection string. Copy the ADO.NET connection string if you intend to use it.


1 Answers

The solution for my problem was selecting "Custom" instead of "SQL Azure" from the "SQL Azure / SQL Server / MySQL / Custom" selector for the Entity Framework connection string, even though the database does run on SQL Azure.

[Edit] From a popular comment by @matthew-steeples below:

I would add to this for anyone else having the same issue is that sometimes the config file will have " instead of ", and the Azure Websites needs those to be changed to "

like image 91
Frank van Eykelen Avatar answered Sep 30 '22 02:09

Frank van Eykelen