identity 2.0 - How to change connection string / DbContext at runtime?

Apr 28, 2014 at 9:15 PM
I would like to do the following in my MVC 5 / identity 2.0 app:
  1. Change the connection string used by the ApplicationDBContext at runtime. I will have numerous clients, each with their own SQL database. So at session start, I need to be able to specify the desired database / connection.
I assume to class ApplicationDbContext that I add the overload.
    public static ApplicationDbContext Create(string connectionString)
        return new ApplicationDbContext(connectionString);
I also am assuming that in Startup.Auth.cs that I need to modify this line to pass in the connection string. If so, then I am having troubles here with doing just that.
Am I going down the right road? Am I missing anything else? I am basically stuck at this point. TIA for your help!!!
May 6, 2014 at 2:21 AM
@TennChris - How do you plan on storing "connection string" per user?
When user logs in, you need to determine the right connection string first - correct?
Which mean you need centralized "tenant" meta db...Or similar...

What I am doing, is that I am using ASP.NET Identity in 1 DB and in another DB I keep customer data (using schema separation).
In this scenario, I customized IdentityUser )call it AppUser) with additional table. Based on your design this can be 1:M (in case where 1 user has access only to 1 other db) or M:M where a user can have access to multiple DB....This approach allows you to have all the info available at the time user logs in in order to connect him/her to correct DB at runtime.