I am experiencing a mental block in searching/finding an example to this scenario.
User-A logs on and connects to "master" database on "abcServer" to verify account. Once approved, server returns connection string for "unique-A" database to user-A on "abcServer".
I know the dbContext in EF has the constructor assigning a connString name, but I want this to be dynamic:
(1) DbContext
// dbContext constructor
public MasterDatabase() : base("name=MasterDatabase")
{
Configuration.LazyLoadingEnabled = false;
}
(2) The default connection is
// web.config
<connectionStrings>
<add name="MasterDatabase" connectionString="Data Source=abcServer;Initial
Catalog=Master;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
But, that is it for the hard coding of connStr. The remainder of the project is about the respective user working with the EF classes in his/her db which won't be determined until return connection string from a successful login. Something like this:
(3) Method in controller changing the conn string
// in api controller, once log in successful, call to method return value as parameter
private void Connect2DbwithThisUsersConnString(string connStr)
{
// change the conn string & USE THIS CONTEXT to this user's db
}
Any asp.net/mvc examples of this? Thanks in Advance. Going nuts here.
Remember: I do not know the connection string until log in. This may be a new user, requiring a new database be created on the fly and that connStr passed along. I cannot hard-code a unique dbContext "base" or conn string.
Many thanks for your attention!