Change Database Source Depending On Login Credentials

I'm a new developer and I'm working on a project that utilizes the SalesForce REST API. A portion of my .Net project involves updating the web.config and the database depending on the login credentials.

For example, client 1 logins in, the are updated with the correct Consumer Key and Client Secret. This client has access to Database1.

Client 2 logs in. are updated appropriately. Now, the Database1 is switched out with Database2, programmatically.

Is there a way to programmatically change the database source depending on login?

Quick edit to my post. Client1 and Client2, in this instance, are two separate companies, that should not have access to each other's databases. I want to be able to utilize the same application for both clients, but update the web.config and the database used, depending on which company logs in.



If you are using L2S or EF, you can create a class within your application that inherits your L2S/EF context class, then make the derived class's constructor do the work of figuring out what connection string to use based on log in and initialize itself. You can then use that derived class as a data source as needed.

Basically, it sounds like you may have a situation where you don't want to be updating the web.config every time you add a new client/database. You'll want to store a template for the connection string in web.config, but not the strings themselves.