How to publish . mdf database in Azure SQL Dabases?

Asked

Viewed 203 times

1

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

1 answer

2

You will have to generate a script from that file MDF and connect to the Azure base using SQL Server Management Studio. The procedure is a bit big and would not fit in the answer (it would have to be a separate answer just for this). As a curiosity, this link has step by step how to attach your MDF in an instance of SQL Server (http://learningsqlserver.wordpress.com/2011/02/13/how-can-i-open-mdf-and-ldf-files-in-sql-server-attach-tutorial-troublshooting/).

Remember that in Azure it is not possible to attach a .mdf. The simplest way is to have SQL Server Management Studio and use the option of deploy from your base to SQL Azure.

Alternatively, you can configure the method Seed of your file Migrations\Configuration.cs for data to be entered into the publication of your system in the Azure cloud:

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" }
        //    );
        //
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.