ConfigurationManager In WPF


Answer :

Just add an app.config and not web.config because it is not a web application.



And after that it's too simple, just add a reference to to System.Configuration and then use this.



var ConnStr = ConfigurationManager.AppSettings["Trackboard"];


I've figured it out!
I shouldn't have created a new config file. There is a default app.config file in the project.
Now everything is fine.


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Trackboard.Properties.Settings.TrackboardConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DATABASE\Trackboard.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

private static string ConnStr = ConfigurationManager.ConnectionStrings["Trackboard.Properties.Settings.TrackboardConnectionString"].ConnectionString;


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable