How to publish .mdf database in Azure SQL Dabases?

1

I have solution with a Asp.Net MVC 5 project and I'm using Code First and Migrations to update the .mdf database automatically generated in the App_Data folder. How do I put this .mdf in Azure and can use it in production?

    
asked by anonymous 15.09.2014 / 20:56

1 answer

2

You will have to generate a script of this MDF file and connect to the Azure database using SQL Server Management Studio. The procedure is kind of big and would not fit in the answer (it would have to be a separate answer just for that). As a curiosity, this link has the step-by-step of how to attach your MDF to an instance of SQL Server ( link ).

Remembering that Azure can not attach a .mdf file. The simplest way is to have SQL SErver Management Studio and use the deploy option of your SQL Azure database.

Alternatively, you can set the Seed method of your Migrations\Configuration.cs file so that the data is inserted into your Azure cloud's publishing system:

internal sealed class Configuration : DbMigrationsConfiguration<Models.ApplicationDbContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
        ContextKey = "SeuSistema.Models.ApplicationDbContext";
    }

    protected override void Seed(SeuSistema.Models.ApplicationDbContext context)
    {
        //  This method will be called after migrating to the latest version.

        //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
        //  to avoid creating duplicate seed data. E.g.
        //
        //    context.People.AddOrUpdate(
        //      p => p.FullName,
        //      new Person { FullName = "Andrew Peters" },
        //      new Person { FullName = "Brice Lambson" },
        //      new Person { FullName = "Rowan Miller" }
        //    );
        //
    }
}
    
15.09.2014 / 21:03