views:

87

answers:

1

Hai, am using c# and wpf

am having my value as a string, i need to call the string value in my app.config file

for example in app.config file am having my connection string. the username may vary diff time. am having the user name as a globasl string. i need to call that string in my app.config connection string when application startup????

A: 

If you change the the database connection-string user/id during the run time, then one solution for you could be to place a "PlaceHolder" inside the config file,

Data Source=MYSERVER\MYINSTANCE;Initial Catalog=MYDB;User ID=%UID%;Password=%PWD%;

When you fetch connection string in your code, replace %UID% and %PWD% with your userid/password.

As a side note, usually, seldom we require the change in uid/pwd during runtime; and that directly inside the config file. Even when needed, its one-time activity, for instance, during installation or everytime user changes the database explicitly, etc. So if you are coming from there, then you can fetch the value during installation and push it inside you config file.

KMan