如何在运行时通过编程方式更改app.config的内容? [英] how to progamatically change the content of app.config at the run time?

查看:133
本文介绍了如何在运行时通过编程方式更改app.config的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处于使用ms sql数据库的程序制作.exe文件后的情况.并且我需要程序在其他计算机上运行...但是数据源因计算机而异...我需要用户提供数据源名称,并且在用户输入数据源名称后,其值app.config中的数据源应被修改..

任何想法...

我也想在网络中使用该程序...即程序安装在局域网中的3-4台计算机中...并且数据库仅安装在主数据库服务器的一台计算机中...其他所有程序计算机使用相同的数据库...在这种情况下如何管理连接字符串?

请帮助
谢谢你
Arpan

I am in a situation that after i make a .exe file of my program that use ms sql database. and i need the program to run in other computer...but the data source differs from computer to computer......i need the user to provide the data source name and after the user enters the data source name the value of data source in app.config should be modified..

any idea...

also i want to use the program in network...ie the program is installed in 3-4 computer which is in lan network...and the database is installed in only one computer the main database server... all program in other computer uses the same database...how can i manage the connection string in this case??

please help
thank u
Arpan

推荐答案

1)在解决方案资源管理器中打开项目属性,然后双击"Settings.settings"
2)在生成的网格中,将名称"更改为"MySetting",然后将值"设置为默认值".分别将类型"和范围"保留为字符串"和用户".
3)保存并关闭设置窗口.
4)阅读设置:
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as "string" and "User" respectively.
3) Save and close the settings window.
4) To read your setting:
string s = Properties.Settings.Default.MySetting;

5)编写设置:

5) To write your setting:

Properties.Settings.Default.MySetting = "My new setting value";
Properties.Settings.Default.Save();


这篇关于如何在运行时通过编程方式更改app.config的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆