Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Machine.config and app.config interview Questions

machine.config related questions

1.  What is machine.config?

The machine configuration file, Machine.config, contains settings that apply to an entire computer. This file is located in the %runtime install path%\Config directory. Machine.config contains configuration settings for machine-wide assembly binding, built-in remoting channels, and ASP.NET.

2.  Where is machine.config?

Machine.config located in below path :

For 32-bit


For 64-bit


[version] should be equal to v1.0.3705, v1.1.4322, v2.0.50727 or v4.0.30319 etc.


App.Config Related questions:

1. What is App.Config?

App.Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.

2.  How to read App.Config?

Once you have defined your app.config, you can read it in code using the ConfigurationManager class.


<?xml version="1.0"?>
  <add name="INTERNALDB" connectionString="Data Source=.\;Initial Catalog=ProductDatabaseUnitTest;Integrated Security=True;" providerName="System.Data.SqlClient"/>
    <add name="TestLiveDB" connectionString="Data Source=.\;Initial Catalog=test LocalDev;Integrated Security=True;" providerName="System.Data.SqlClient" />


    /// <summary>
    /// Gets theInternalDBConnection.
    /// </summary>
        public string InternalDataBaseConnection
            get { return ConfigurationManager.ConnectionStrings["INTERNALDB"].ConnectionString; }


3.  How to Change connection string & reload app.config at run time?

You can change connections string at runtime using following code:
     var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     var connectionStringsSection = (ConnectionStringsSection)config. GetSection("connectionStrings");
                connectionStringsSection.ConnectionStrings["Blah"].ConnectionString = "Data Source=blah;Initial Catalog=blah;UID=blah;password=blah";