我可以将它存储在app.config中吗? [英] Can I store this in app.config?

查看:63
本文介绍了我可以将它存储在app.config中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储以下内容我的app.config

文件:


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

< configuration>


< appSettings>

< add key =" DEBUG" value =" true" />

< add key =" DEBUGCleanFile" value =" true" />

< / appSettings>


< DataGridColumnCollection>

< AGrid value =" true">

< / AGrid>

< BGrid value =" false">

< column1 value =" true" />

< column2 value =" true" />

< column3 value =" true" />

< / Bgrid>

< / DataGridColumnCollection>


< system.diagnostics>

< /system.diagnostics>

< / configuration>


我特别想要DataGridColumnCollection部分。我可以使用XMLDocument对象从文件中读取

数据。然而,

奇怪的事情发生了。例如,在这一行:


使用(SqlConnection连接=新的SqlConnection(connectionString))


我得到这个例外:


''System.Data.SqlClient.SqlConnection'的类型初始化程序抛出了

异常。


该应用程序.config和以上行完全不相关。当我删除DataGridColumnCollection的

时,一切都很好,但当然我放松了所有这些数据。现在,我正在使用我自己的XML文件,但这只是更多的文件。关于如何将

DataGridColumnCollection部分粘贴到app.config中的任何建议?


谢谢,

Brett

I''d like to store something such as the following the my app.config
file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="DEBUG" value="true"/>
<add key="DEBUGCleanFile" value="true"/>
</appSettings>

<DataGridColumnCollection>
<AGrid value="true">
</AGrid>
<BGrid value="false">
<column1 value="true"/>
<column2 value="true"/>
<column3 value="true"/>
</Bgrid>
</DataGridColumnCollection>

<system.diagnostics>
</system.diagnostics>
</configuration>

I particularly want the DataGridColumnCollection section. I can read
the data fine out of the file using an XMLDocument object. However,
weird things happens. For example, on this line:

using(SqlConnection connection = new SqlConnection(connectionString))

I get this exception:

The type initializer for ''System.Data.SqlClient.SqlConnection'' threw an
exception.

The app.config and above line are completely unrelated. When I remove
the DataGridColumnCollection, everything is fine but of course I loose
all of that data. For now, I''m using my own XML file but that is just
more files to haul around. Any suggestions on how I can stick the
DataGridColumnCollection section into app.config?

Thanks,
Brett

推荐答案

Hello Brett,


DataGridColumnCollection是一个类,据我所知?

然后序列化并保持编码就像一个字符串


BRI'想要存储以下内容我的app.config

BRfile:

BR>

BR<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

BR< configuration>

BR< appSettings>

BR< add key =" DEBUG" value =" true" />

BR< add key =" DEBUGCleanFile" value =" true" />

BR< / appSettings>

BR< DataGridColumnCollection>

BR< AGrid value =" true" ;>

BR< / AGrid>

BR< BGrid value =" false">

BR< column1 value =" true" />

BR< column2 value =" true" />

BR< column3 value =" true" />

BR< / Bgrid>

BR< / DataGridColumnCollection>

BR< system.diagnostics>

BR< /system.diagnostics>

BR< / configuration>

BRI尤其需要DataGridColumnCollection部分。我可以

使用XMLDocument对象将数据清理干净。

BR但是,奇怪的事情发生了。例如,在这一行:

BR>

BRusing(SqlConnection connection = new

BRSqlConnection(connectionString))

BR>

BRI得到此例外:

BR>

BR''System.Data.SqlClient.SqlConnection''的类型初始值设定项扔了

BRan例外。

BR>

BR app.config及以上行完全不相关。当我支持
BRremove DataGridColumnCollection时,一切都很好但是

BRcourse我放弃了所有这些数据。现在,我正在使用我自己的XML文件

BRbut这只是更多的文件。关于

BRI如何将DataGridColumnCollection部分粘贴到app.config中的任何建议?

BR>

BRThanks,

BRBrett

---

WBR,

Michael Nemtsev ::博客: http://spaces.msn.com/laflour


有时一个人仍然忠诚于一个原因只是因为它的对手不会因为b b不再平淡无味。 (c)Friedrich Nietzsche
Hello Brett,

DataGridColumnCollection is a class, as I understand?
Then serialize it and keep it encoded just like a string

BRI''d like to store something such as the following the my app.config
BRfile:
BR>
BR<?xml version="1.0" encoding="utf-8" ?>
BR<configuration>
BR<appSettings>
BR<add key="DEBUG" value="true"/>
BR<add key="DEBUGCleanFile" value="true"/>
BR</appSettings>
BR<DataGridColumnCollection>
BR<AGrid value="true">
BR</AGrid>
BR<BGrid value="false">
BR<column1 value="true"/>
BR<column2 value="true"/>
BR<column3 value="true"/>
BR</Bgrid>
BR</DataGridColumnCollection>
BR<system.diagnostics>
BR</system.diagnostics>
BR</configuration>
BRI particularly want the DataGridColumnCollection section. I can
BRread the data fine out of the file using an XMLDocument object.
BRHowever, weird things happens. For example, on this line:
BR>
BRusing(SqlConnection connection = new
BRSqlConnection(connectionString))
BR>
BRI get this exception:
BR>
BRThe type initializer for ''System.Data.SqlClient.SqlConnection'' threw
BRan exception.
BR>
BRThe app.config and above line are completely unrelated. When I
BRremove the DataGridColumnCollection, everything is fine but of
BRcourse I loose all of that data. For now, I''m using my own XML file
BRbut that is just more files to haul around. Any suggestions on how
BRI can stick the DataGridColumnCollection section into app.config?
BR>
BRThanks,
BRBrett
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


我没有使用那个班级。我们称之为MyDataGridColumnCollection。我

仍然得到sqlclient异常。


谢谢,

Brett

I''m not using that class. Let''s call it MyDataGridColumnCollection. I
still get the sqlclient exception.

Thanks,
Brett


Brett,

如果要在配置文件中存储自定义XML元素/节点,

它们必须是可识别元素或简单键= x value = y元素

appSettings部分。

否则,你需要在

配置中声明一个自定义配置部分并拥有一个自定义的sectionhandler来读取它。迈克尔关于

序列化课程的评论是正确的。

显然,需要进行一些研究,但如果这是你想要的方式

存储您的自定义数据,值得。

Peter


-

联合创始人,Eggheadcafe。 com开发人员门户网站:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com



" Brett Romero"写道:
Brett,
If you want to store custom XML elements/ nodes in a configuration file,
they must either be recognized elements, or simple key=x value=y elements in
the appSettings section.
Otherwise, you need to declare a custom configuration section in your
config and have a custom sectionhandler to read it. Michael''s comments about
serializing a class are correct.
Obviously, some study will be required but if this is the way you want to
store your custom data, it will be worth it.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brett Romero" wrote:

我想存储以下内容我的app.config

文件:


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

< configuration>


< appSettings>

< add key =" DEBUG" value =" true" />

< add key =" DEBUGCleanFile" value =" true" />

< / appSettings>


< DataGridColumnCollection>

< AGrid value =" true">

< / AGrid>

< BGrid value =" false">

< column1 value =" true" />

< column2 value =" true" />

< column3 value =" true" />

< / Bgrid>

< / DataGridColumnCollection>


< system.diagnostics>

< /system.diagnostics>

< / configuration>


我特别想要DataGridColumnCollection部分。我可以使用XMLDocument对象从文件中读取

数据。然而,

奇怪的事情发生了。例如,在这一行:


使用(SqlConnection连接=新的SqlConnection(connectionString))


我得到这个例外:


''System.Data.SqlClient.SqlConnection'的类型初始化程序抛出了

异常。


该应用程序.config和以上行完全不相关。当我删除DataGridColumnCollection的

时,一切都很好,但当然我放松了所有这些数据。现在,我正在使用我自己的XML文件,但这只是更多的文件。关于如何将

DataGridColumnCollection部分粘贴到app.config中的任何建议?


谢谢,

Brett

I''d like to store something such as the following the my app.config
file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="DEBUG" value="true"/>
<add key="DEBUGCleanFile" value="true"/>
</appSettings>

<DataGridColumnCollection>
<AGrid value="true">
</AGrid>
<BGrid value="false">
<column1 value="true"/>
<column2 value="true"/>
<column3 value="true"/>
</Bgrid>
</DataGridColumnCollection>

<system.diagnostics>
</system.diagnostics>
</configuration>

I particularly want the DataGridColumnCollection section. I can read
the data fine out of the file using an XMLDocument object. However,
weird things happens. For example, on this line:

using(SqlConnection connection = new SqlConnection(connectionString))

I get this exception:

The type initializer for ''System.Data.SqlClient.SqlConnection'' threw an
exception.

The app.config and above line are completely unrelated. When I remove
the DataGridColumnCollection, everything is fine but of course I loose
all of that data. For now, I''m using my own XML file but that is just
more files to haul around. Any suggestions on how I can stick the
DataGridColumnCollection section into app.config?

Thanks,
Brett


这篇关于我可以将它存储在app.config中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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