0

Everything works great when I run my project locally, but when I deploy to Azure I get the following error.

"Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception."

My connection string is:

add name="LifeEntities" connectionString="Server=tcp:abc000000ab.database.windows.net,1433;Database=Life;User ID=myid@abc000000ab;Password=mypw;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient"

I'm getting this error when my code tries to open the context of my entity framework database. Note, that I'm using a pretty basic MVC project template that does ASP.NET Identity as well.

I've read that this is because of code first vs data but not sure how to solve this issue.

1 Answer 1

1

That's a pure SQL connection string. You need to use a EF connection string, including the model metadata etc.

Here's an example:

<add name="Context" connectionString="metadata=res://*/Context.csdl|res://*/Context.ssdl|res://*/Context.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=Context;integrated security=True;MultipleActiveResultSets=True;&quot;" providerName="System.Data.EntityClient" />
Sign up to request clarification or add additional context in comments.

6 Comments

I've seen this before but what do I use for the data source on an azure website? Locally I have data source=(LocalDb)\v11.0;attachdbfilename=|DataDirectory|\aspnet-MMO-20140404072409.mdf
Got it figured out. Now I'm getting an Access is Denied so need to figure out the permissions.
You probably haven't opened up the database in the firewall correctly. You would need to fix that in the Azure portal.
I did that, but I was mixing connection strings between the ASP.NET Identity tables vs my custom tables. I created a separate connection string for my tables since for those I use a database first and the Identity stuff is code first and I guess they don't like mixing via the connection string.
so what is the correct syntax for EF connection string when your database is in azure?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.