views:

86

answers:

1

I've been given the task of creating a site that will allow our various large clients to log into our website and click on our various pages to view analytics data based on their sales.

Does anyone have any idea about the best way to handle multiple databases based off the user? Lets say we have 3 big name clients, the design decision has been made each big client has their own database.

If a user from clientA logs into our system they should see the analytics for their company, and the model should be pulling down from clientA's data context. Likewise, if someone logs in and they are associated with clientB in the database then they need to have their data pulled from that data context.

If I can, I would like to have one Data Access Layer class written in LINQ and have some way of passing in the associated DataContext with that user when they login. Can anyone think of an appropriate or clean way to do this?

+6  A: 

If the schema's are the same for all databases, then it's very simple. The datacontext has an overload which takes a connection string. Simply store the various connection strings in some centralized location (database, XML, resource, whatever) and then just create one datacontext with that connection string which you can then use regardless of who's connected.

BFree
The question I have is how do I handle switching the datacontext or using a different one based on that particular user.
I agree with BFree. Your pivot point is going to be the connection string.
Robert Harvey
@TankMan: It's all in the connection string. If you detect that a different user has connected, get the connection string for them, and just new up a DataContext with that connection string.
BFree