开发者

How to Call my global value in app.config file

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 开发者_如何学Gostring. i need to call that string in my app.config connection string when application startup????


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜