2

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.

6
  • you are using migrations in your database? your database has a mi migration table ? Commented Feb 12, 2014 at 14:10
  • I'm not using any migrations that I'm aware of. But there is a "__MigrationHistory" table created in the database on my dev machine, even though the database is created from scratch. Does that mean anything? Commented Feb 12, 2014 at 14:36
  • The only customization I'm doing that I'm aware of is using Fluent API in my DbContext subclass, where I'm overriding the OnModelCreating method. Commented Feb 12, 2014 at 14:38
  • You have information in your database or is empty? I tell you this because i had a similar problem, and is has to related with entity framework database initializer. Commented Feb 12, 2014 at 15:13
  • Disable migration and delete your database, then launch your application and check if your database dont have the _MigrationHistory table. Then try again. Commented Feb 12, 2014 at 15:16

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. I'm not using migrations though. I wasn't able to solve this and ended up manually creating the database on Azure by generating a script of the database on my dev machine.

Your Answer

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