Click here to Skip to main content
15,354,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

In my project there is a requirement that I have to connect different databases for different users. So for that I need to know how can I change connection string in web.config at runtime for particular session.

My Scenario is like this.

Any user come and login with his login ID and Password and Select Company Name from the drop down list after that we retrieve proper details from the database means his "Connection String" or "Database Details".
After that I have to change the connection string in web.config according to his database details. Because Every user of different company have different database.

Note:
I'm using Microsoft Enterprise library for database connection in my project. So I need to paas connection string key in web.config file or I can pass it on code behind as well.

Please Help me in this..
Posted

1 solution

You don't have to change web.config at runtime. You could store all connection strings with different names and select the one you need depending on logged in user.
   
Comments
AmarSinghRawat 1-Dec-11 23:36pm
   
Thanks for reply mjbohn.. but in my requirement connection strings are many and comes from database.
Luceefer 30-Dec-16 0:06am
   
Thanks mjbohn..
But what if i have multiple users..So it is not feasible to " store all connection strings with different names and select the one you need depending on logged in user."
any other solutions to this problem please.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900