title: Dynamically Set Connection String in Entity Data Model in C#
body: <p>I'm working on a project that relies on the ADO.NET Entity Data Model. I have 4 identical database schemas, one for each department in my company (Marketing, Finanace, Administrative, and HR). I currently know which which department each of my users resides in. I would like to use the department to determine which database the user can connect to.</p>
  
  <p>In C# code, how do I set the connection string at runtime? Currently, I have</p>
  
  <pre><code>string connectionString = GetUsersConnectionString();
  using (MyEntities entities = new MyEntities())
  {
    MyDataEntity myDataEntity = new MyDataEntity();
  
    // Save to the database
    entities.MyDataEntity.Add(myDataEntity);
    entities.SaveChanges();
  }
  </code></pre>
  
  <p>What am I missing here? How do I set the connection string of <code>MyEntities</code> to <code>connectionString</code>?</p>