Tech Talk A software developer on all things tech, and then some

12Jan/112

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();
Comments (2) Trackbacks (0)
  1. Very informative post. It is very simple and understandable due to which it’s more helpful for beginner as me as well as developer. I have found a nice post too over the internet which also explained very well. For more information of that post check out this link…
    http://www.mindstick.com/Articles/6053eec1-02c0-4e09-ab74-c288d8ed41b6/?Connection%20String%20using%20App.config

    Thanks everyone for your precious post!


Leave a Reply

No trackbacks yet.

%d bloggers like this: