0

How to configure Entity Framework to use different connection string when executing migrations and when working with the database.

The reason for that is quite simple, I do not want to have sa login for the website, but I want to be able to execute migrations.

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42
d.popov
  • 4,175
  • 1
  • 36
  • 47

1 Answers1

0

After not finding anything on the web for how to do that, the Object Explorer helped.

The EF Migration Configuration class (where AutomaticMigrationsEnabled = true is set) has also a property named TargetDatabase.

This can be set to whatever connection string you want like so:

TargetDatabase = new System.Data.Entity.Infrastructure.DbConnectionInfo(
            ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString,
            ConfigurationManager.ConnectionStrings["ConnString"].ProviderName);
d.popov
  • 4,175
  • 1
  • 36
  • 47