C#配置管理器。的ConnectionStrings

编程入门 行业动态 更新时间:2024-10-24 14:17:23
本文介绍了C#配置管理器。的ConnectionStrings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含包含一个连接字符串,应用程序配置文件控制台应用程序如下图所示:

I have a console app containing an application configuration file containing one connection string as shown below:

<configuration> <connectionStrings> <add name="Target" connectionString="server=MYSERVER; Database=MYDB; Integrated Security=SSPI;" /> </connectionStrings> </configuration>

当我使用它传递给我的连接方式:

When I pass this to my Connection using:

ConfigurationManager.ConnectionStrings[1].ToString()

我有两个值在那里,因此使用集合中的第二个,我的问题是,什么是第二次来的?

I have two values in there, hence using the second in the collection, my question is where is this second coming from?

我已经检查了\\ BIN的版本和原来和我无关!它显然是一个系统生成的一个,但我还没有见过这个?任何人都可以告诉我吗?

I have checked the \Bin version and original and its not mine! Its obviously a system generated one but I have not seen this before? Can anyone enlighten me?

神秘的连接字符串是:

data source=.\SQLEXPRESS; Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf; User Instance=true

这是不是一个问题,因为这样我只是想知道这是为什么出现?在此先感谢!

This isn't a problem as such I would just like to know why this is occuring? Thanks in advance!

有关备查那些谁可能会或可能不会在这个绊倒,发现了的machine.config ,它变得很明显这是不好的做法,通过指一个配置后,其作为每个堆栈索引将可能是不同的,这就是为什么密钥被使用。

For future reference to those who may or may not stumble on this, after discovering the machine.config, it's become apparent it is bad practice to refer to a config by its index as each stack will potentially be different, which is why "Keys" are used.

在这种情况下我的code将是:

In this instance my code would be:

ConfigurationManager.ConnectionStrings["Target"].ToString()

干杯所有!

推荐答案

检查的machine.config 。如果你只想要你进入,你可以添加一个&LT;清/&GT; 元素添加到&LT;是connectionStrings&GT; 像这样的元素...

Check your machine.config. If you only want your entry, you can add a <clear /> element to the <connectionStrings> element like so ...

<connectionStrings> <clear /> <add name="Target" connectionString= "server=MYSERVER; Database=MYDB; Integrated Security=SSPI;" /> </connectionStrings>

更多推荐

C#配置管理器。的ConnectionStrings

本文发布于:2023-11-08 11:16:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   ConnectionStrings

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!