Getting the Connection String From Your App.Config In WPF and C#

I am using Active Reports and came across a problem where I needed to send the report a connection string. Before I would build the connection string based on what database was used, etc… from an INI file. Now we moved to a MvvM structure with the connection string in the App.Config. I had found a common solution :

ConfigurationSettings.AppSettings["ConnectionString"];

This worked for earlier versions, but I am currently using .Net 4.0. Since I was using WPF, I added the reference to System.Windows.Forms then referenced it. Then I used the following code :

//sqlDBDataSource is a Connection string property for the Active Reports
//Demo is the name of my project in DemoDatabaseSetting
sqlDBDataSource.ConnectionString = ConfigurationManager.DemoDatabaseSetting.ToString();

Releated Post

2 thoughts on “Getting the Connection String From Your App.Config In WPF and C#

Leave a Reply

%d bloggers like this: