0

I have mvc application. I'm using code first approach. When new tenant registers to system i create new database with azure sql fluent api.

Database is created without problem but it's empty as expected. To initialize data from my migration i call myDB.Database.Initialize(true); it passes without any error but tables are not created.

To be sure i run project in my local computer and point connection string to azure database after running myDB.Database.Initialize(true); database is initialized.

I researched on internet people points to timeout issue for applying migration.Even i don't have any timeout issue extended timeout for migration but still same.

It creates table when i run from my computer (connected to azure db) but doesn't create when running on azure even i don't see any error.

Any idea why it's not creating on azure sql database ?

Tried to change timeout for migration configuration.

Cozdemir
  • 177
  • 2
  • 19
  • Check migrantion table if that exists and anything in there. Does the user you use to connect to the db has dbo access? Do you get any error? – Junaid Jul 13 '19 at 17:55
  • Hello, When table is created its blank without any table. As i know it should be filled with talbes based on migration configuration files and database context. it does when i run from local without any problem. by local i mean i run visual studio but connection is pointed to azure sql database – Cozdemir Jul 13 '19 at 18:10
  • Have you tried [these steps](https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application)? – Steve Greene Jul 14 '19 at 16:07
  • When you run local with connection pointed to azure sql, it is same as on azure. – Joey Cai Jul 15 '19 at 02:49
  • 1
    Thanks eveyone for help. I solved my problem with following thead. I think my problem was because my applications is multi tenant. i connect to database with connection string dynamicly. Each tenant connects to his/her database via connection string dynamicly. So connection strings was not in my webconfig. That's why i needed to specify connection string. And above thread is exactly about that. I implemented that code and it worked. https://stackoverflow.com/questions/14710758/ef-code-first-migratedatabasetolatestversion-accepts-connection-string-name-from/16163466#comment100576183_16163466 – Cozdemir Jul 15 '19 at 17:16
  • @Cozdemir I'm glad you figured out your issue! Please consider posting this as an answer as it helps other people in the same situation find the solution. – PerfectlyPanda Jul 15 '19 at 17:33
  • Hi @Cozdemir, I helped you post this as the answer, you can accept it as answer( click on the check mark beside the answer to toggle it from greyed out to filled in.). This can be beneficial to other community members. Thank you. – Leon Yue Jul 17 '19 at 01:07

1 Answers1

1

According to @Cozdemir's comment:

I solved my problem with following thead. I think my problem was because my applications is multi tenant. i connect to database with connection string dynamicly. Each tenant connects to his/her database via connection string dynamicly. So connection strings was not in my webconfig. That's why i needed to specify connection string. And above thread is exactly about that. I implemented that code and it worked. Reference: EF Code First MigrateDatabaseToLatestVersion accepts connection string Name from config

I posted this as answer and this can be beneficial to other community members.

Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
Leon Yue
  • 15,693
  • 1
  • 11
  • 23