user1379417
user1379417

Reputation:

Tables not created with Entity Framework on Azure

I am using Entity Framework using Code First and the Fluent API.

When developing on my local machine, the database and tables are created as expected and everything works fine.

When deploying to my Azure web role the database is created, but the tables are never created. If I try a HTTP request touching DbContext, the request times out and finally my web role only returns "Service Unavailable".

The model is large, but not extremely so (43 tables are created on my dev machine).

What can be wrong here? Here is my Azure SQL connection string, where you can see that I set the timeout quite high:

<add name="MyConnectionString" connectionString="Server=tcp:myserveronazure.database.windows.net,1433;Database=MyDatabase;User ID=MyUser@myserveronazure;Password=thepassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=120;PersitSecurityInfo=true;" providerName="System.Data.SqlClient" />

EDIT: After RDP:ing into the Azure VM, I see in the Event Log that w3wp.exe (the IIS worker process, if I'm not mistaken) crashes. The log doesn't list any error message.

Upvotes: 2

Views: 1365

Answers (1)

emcas88
emcas88

Reputation: 901

Enityframework have three Database Initializer by default CreateDatabaseIfNotExists,DropCreateDatabaseWhenModelChanges and DropCreateDatabaseAlways that are executed when you hit the context for the first time, if you are using migrations (i think is the case) you must use the MigrateDatabaseToLatestVersion initializer to work in the application deployment. Hope it works!

Upvotes: 1

Related Questions