如何更改config.web文件 [英] how to change config.web file

查看:50
本文介绍了如何更改config.web文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< configuration>

< appSettings />

< connectionStrings>

< add name =" pedbConnectionString" connectionString =" Data Source = localhost; Initial Catalog = acsdb; Persist Security Info = True; User ID = sa; Password = password123"

providerName =" System.Data.SqlClient" />

< / connectionStrings>



我想更改初始目录,让我们说pedb?我该怎么做?




之前:

< add name =" pedbConnectionString" connectionString =" Data Source = localhost; Initial Catalog = acsdb; Persist Security Info = True; User ID = sa; Password = password123"


After:

< add name =" pedbConnectionString" connectionString =" Data Source = localhost; Initial Catalog = pedb; Persist Security Info = True; User ID = sa; Password = password123"


提前感谢

解决方案

config.web不应该被它自己运行的代码改变。

自修改代码很顽皮。

你可以做的就是这样存储:

展开 | 选择 | Wrap | 行号


但是,如果你想修改另一个应用程序的代码(比如启动单独的EXE来改变原始配置文件),尝试使用网站的System.Web.Configuration.WebConfigurationManager对象,或Windows应用程序的System.Configuration.ConfigurationManager对象(记得包含System.Configuration引用)。


这些对象的'Open ...()方法将为您提供一个System.Configuration.Configuration对象,它可以很好地解析所有配置信息:)


我有一个漂亮的我可以在这里粘贴的课程,但这会打败目的,现在不会吗?


快乐狩猎!



config.web不应该被它自己运行的代码改变。

自修改代码很顽皮。

你是什么可以做的就是像这样存储它:

展开 | 选择 | Wrap | 行号

<configuration>
<appSettings/>
<connectionStrings>
<add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=acsdb;Persist Security Info=True;User ID=sa;Password=password123"
providerName="System.Data.SqlClient" />
</connectionStrings>



i want to change the initial catalog to lets say pedb? how do i do tat?




Before:
<add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=acsdb;Persist Security Info=True;User ID=sa;Password=password123"

After:
<add name="pedbConnectionString" connectionString="Data Source=localhost;Initial Catalog=pedb;Persist Security Info=True;User ID=sa;Password=password123"


thanks in advance

解决方案

config.web should not be changed by it''s own running code.
Self-modifying code is naughty.
What you could do is store it like this:

Expand|Select|Wrap|Line Numbers


BUT, if you are trying to modify another application''s code (like firing a seperate EXE to change the original config file), try using the System.Web.Configuration.WebConfigurationManager object for websites, or System.Configuration.ConfigurationManager object for windows apps (remember to include System.Configuration reference).

These objects'' Open...() methods will give you a System.Configuration.Configuration object, which has all the configuration information parsed quite nicely :)

I have a nifty class which I could paste here, but that would defeat the purpose, now wouldn''t it?

Happy hunting!


config.web should not be changed by it''s own running code.
Self-modifying code is naughty.
What you could do is store it like this:

Expand|Select|Wrap|Line Numbers


这篇关于如何更改config.web文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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