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.
In C# code, how do I set the connection string at runtime? Currently, I have
string connectionString = GetUsersConnectionString();
using (MyEntities entities = new MyEntities())
{
MyDataEntity myDataEntity = new MyDataEntity();
// Save to the database
entities.MyDataEntity.Add(myDataEntity);
entities.SaveChanges();
}
What am I missing here? How do I set the connection string of MyEntities
to connectionString
?