Azure: The context is being used in Code First mode with code that was generated from an EDMX

azure connection-string database entity-framework-6

Question

I have MVC app running fine in local. After updating to Azure, it started throwing the error:

The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project.

I have checked if there is any difference between the local web.config and azure web.config. except the credentials, everything is same. And it read:

<add name="DBEntities" 
     connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;
                       provider=System.Data.SqlClient;
                       provider connection string=&quot;data source=xx;initial catalog=xx;persist security info=True;user id=xx;password=xx;MultipleActiveResultSets=True;application name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

I am using EF 6.1.3, MVC5

1
4
12/9/2015 3:28:18 PM

Accepted Answer

Found a simpler solution than adding all the stuff in the Azure connection string. I just changed the connection string name in Azure. It worked..

0
7/13/2015 10:31:14 AM

Popular Answer

I ran into the same error message and managed to solve it with the help of this post here on StackOverflow.

In the Azure Management / Web Apps / [Your web app] / CONFIGURE / connection strings , make sure of 3 things :

  1. The connection string has the same name as the connection string in your project.

  2. The connection string Value contains all of the metadata as appears in the connection string in your project. Mine looks like this:

    metadata=res://\*/Models.[MyModel].csdl|res://\*/Models.[MyModel].ssdl|res://\*/Models.[MyModel].msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:[myDBServer].database.windows.net,1433;Database=[myDB];User ID=[myDBUser]@[myDBServer];Password=[myPassword];Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"

  3. The third column (default set to SQL Database) is set to Custom



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow