0

I am trying to set the connection string dynamically in my database first MVC web applications. This is the code that I've come up with but it keeps erroring with

Keyword not supported: 'metadata'.

I'm aware that there are other similar qustions on Stackoverflow but none of the solutions have solved my problem
This is the code that I'm using

public partial class DevTS_mtEntities : DbContext
{

    public DevTS_mtEntities(string conn)
    {

        this.Database.Connection.ConnectionString = "metadata=res://*/Setup.Questions.Questions.csdl|res://*/Setup.Questions.Questions.ssdl|res://*/Setup.Questions.Questions.msl;provider=System.Data.SqlClient;provider connection string=\"data source=<server>;initial catalog=DevTS_mt;user id=<user>;password=<password>;MultipleActiveResultSets=True;App=EntityFramework\"";

    }

}
Matt
  • 215
  • 1
  • 11
  • this the edmx generated connection string. It contains a connection string that you need to pull out of it. This is your connection string "data source=;initial catalog=DevTS_mt;user id=;password=;MultipleActiveResultSets=True;" – Fran May 17 '18 at 13:55
  • @Fran I tried that and it now says 'The 'data source' keyword is not supported.' – Matt May 17 '18 at 14:00
  • 1
    Possible duplicate of [Setup Entity Framework For Dynamic Connection String](https://stackoverflow.com/questions/14440698/setup-entity-framework-for-dynamic-connection-string) – Fran May 17 '18 at 14:05
  • See the duplicate. Don't set it yourself in the constructor, call the base constructor to do that. – Fran May 17 '18 at 14:07
  • @Fran I already tried it but I got another error 'The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. ' – Matt May 17 '18 at 14:12

0 Answers0