views:

569

answers:

1

I have an app.config file inside my TestProject, but when I try to read it using ConfigurationManager it reads from somewhere else and it's none of my app.config's. How to correct this?

Current config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="Production" connectionString="Server=127.0.0.1,2345;Uid=user;Pwd=password;Initial Catalog=DATABASE_DATA"/>
  </connectionStrings>
</configuration>

Current code:

ConfigurationManager.ConnectionStrings[0].ConnectionString

Expected output:

"Server=127.0.0.1,2345;Uid=user;Pwd=password;Initial Catalog=DATABASE_DATA"

Actual output:

"data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
+4  A: 

Try Referencing it by name.

ConfigurationManager.ConnectionStrings["Production"].ConnectionString

The config files automatically integrate machine.config which has that SQLEXPRESS connection string by default.

Jason Punyon