Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to connet to database server with different hosts. I will change the host frequently by iteretaing through some data. How can i make the connection string dynamic so that i can change the host name whenever I need.

Also the username and password in the connection string is same throughout all hosts.I need to encrypt the username and password in the connection string. Please guide in this too.
Posted
Comments
wizardzz 27-Apr-12 11:37am    
This will be easier to help with if you provide some code.

1 solution

The connection string is just a string. It's very simple string manipulation to change the server name in a connection string. I would suggest just putting a known tag in the connection string in place of an actual server name. When you want to change the server name, it's a very simple call to the Replace method on the string to replace the known tag with the server name.

As for encrypting the username and password, you don't. You encrypt the entire connection string in your app.config file. Read this[^].
 
Share this answer
 

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