Configure multiple database Entity Framework 6

后端 未结 3 598
予麋鹿
予麋鹿 2020-11-30 03:18

In my solution I have 2 projects that use Entity Framework 6. Each points to a different database, both using the same data provide - SQL Server. A third project in my solut

3条回答
  •  隐瞒了意图╮
    2020-11-30 03:59

    Connection string of EntityFramework 6 should be inside configuration file that located (alert!) in execution folder. For example OP have multiple projects in solution, so the connection string must be in configuration file belongs to main executive project.

    Now, if you want to define connection string in your code, you can make fake connection string in configuration file and give your entity's instance new connection string:

    DBEntities e = new DBEntities();
    e.Database.Connection.ConnectionString = "Data Source=MyServ;Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=***;Application Name=MyApp";
    

提交回复
热议问题