Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: , +
Hi all,
I understand that its always good practice to keep the connection string in app.config file.
Here, i have 2 doubts:-
1. In my user login screen,
user is selecting the Database Name from a combo box.
So how to keep the selected database name as part of the connection string in the app.config file.
What is the best solution to my problem?..

2. If user also enter the Database passsword also (not the user pwd for login authentication),
how to attach it to app.config duly encrypted?

hope someone can guide me..
thanks
Jim
Posted

1 solution

A config file can contain many connection strings - all you need is a separate setting for each, or a single setting, and concatenation characters. You can then split the separate settings using the string.Split method.
One way to do it would be to store your strings as:
NameOfConnection:ConnectionString|NameOfConnection:ConnectionString|...
You can then split the string on '|', and break the result into a name / value pair on the first ':'
 
Share this answer
 
Comments
jim1972 16-Sep-13 20:21pm    
I still think this wont solve my problem.
My case is this is going to be used in a system where i don't know the server name and
database name. also this may be installed in many places.
In that case, if end user gives server name and db name as user input, how to achieve the result?. any better alternative?..
OriginalGriff 17-Sep-13 4:03am    
Why won't this work? Is there anything in the rule book which says "I must not alter values in app.config" - because if there was, there would be 1) no point in having application configuration files, and 2) a lot of programs that don't work any more...

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