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();

Jacob Saylor

Software developer in Kentucky

2 Responses

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: