C# Configuration Manager . ConnectionStrings
Posted
by Yoda
on Stack Overflow
See other posts from Stack Overflow
or by Yoda
Published on 2010-05-13T15:33:13Z
Indexed on
2010/05/13
15:44 UTC
Read the original article
Hit count: 283
c#
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?
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?
The mystery connection string is:
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!
For future reference to those who may or may not stumble on this, after discovering the machine.config its 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.
Cheers all!
© Stack Overflow or respective owner