Azure: Context is being used in Code First with code that was generated from EDMX

I have an MVC application running fine in local mode. After upgrading to Azure, it started giving error:

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

I checked if there is any difference between local web.config and azure web.config. except for credentials, everything is the same. And he 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

+3


source to share


4 answers


Found an easier solution than adding all the stuff to the Azure connection string. I just changed the name of the connection string in Azure. It worked.



0


source


I ran into the same error message and was able to solve it with the help of fooobar.com/questions/787761 / ... .

In Azure Management Applications / Web Apps / [Your Web Application] / CONFIGURE / connection, make sure you have three things:



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

  • Connection string The value contains all the metadata that 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;"

  • The third column (default for SQL Database) is set to Custom

+7


source


I had to solve the same problem. The solution was

  • Connecting to a website using FTP
  • Change web.config
  • Add the following connection string:

    Add name = "NewDatabaseEntities" connectionString = "metadata = res: ///NewDatabase.csdl | res: ///NewDatabase.ssdl | res: //*/NewDatabase.msl; provider = System.Data.SqlClient provider connection string = "Data source = tcp: your .database.windows.net, 1433; home directory = yours; integrated security = False; User Id = your; Password = your; MultipleActiveResultSets = True; App = EntityFramework "" providerName = "System.Data.EntityClient"

Thanks to Microsoft for poorly documenting the EntityFramework database First on Azure.

0


source


You need to change this line metadata=res:///NewDatabase.csdl|res:///NewDatabase.ssdl|res://*/NewDatabase.msl;


for the image metadata=res://*/;

0


source







All Articles