DekGenius.com
[ Team LiB ] Previous Section Next Section

Configuration Files

Configuration files are XML-based files that can be used to store application settings so that they can be changed as needed without recompiling the application. The Windows Forms and Web Forms solutions each use a configuration file to store all configuration settings.

The configuration file for all Web Forms solutions contains the following elements.

Web.config

<appSettings>
  <add key="DataConnectString"
    value="Data Source=(local);user id=sa;password=;Initial Catalog=Northwind;" />
</appSettings>

The configuration file for all Windows Forms solutions follows.

App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="Project_Directory" value="c:\\AdoDotNetCookbook\\CS\\" />
    <add key="Temp_Directory" value="c:\\temp\\" />
 
    <add key="Sql_ConnectString" value=
      "Data Source=(local);user id=sa;password=;Initial Catalog=Northwind;" />
    <add key="Sql_SqlAuth_ConnectString" value=
      "Data Source=(local);Initial Catalog=Northwind;User ID=sa;password=;" />
    <add key="Sql_Master_ConnectString" value=
      "Data Source=(local);Integrated security=SSPI;Initial Catalog=master;" />
    <add key="Sql_Msde_ConnectString" value="Data Source=(local)\vsdotnet;
      Integrated security=SSPI;Initial Catalog=Northwind;" />

    <add key="OleDb_ConnectString" value="Provider=SQLOLEDB;
      Data Source=(local);Integrated Security=SSPI;Initial Catalog=Northwind;" />
    <add key="OleDb_SqlAuth_ConnectString" value="Provider=SQLOLEDB;
      Data Source=(local);Initial Catalog=Northwind;User ID=sa;password=;" />
    <add key="OleDb_Oracle_ConnectString" value=
      "Provider=MSDAORA;Data Source=ORCL;User Id=scott;Password=tiger;" />
    <add key="OleDb_Shape_ConnectString" value="Provider=MSDataShape;
      Data Provider=SQLOLEDB;Data Source=(local);
      Initial Catalog=Northwind;Integrated Security=SSPI;" />
    <add key="OleDb_Msde_ConnectString" value="Provider=SQLOLEDB;
      Data Source=(local)\vsdotnet;Integrated security=SSPI;
      Initial Catalog=Northwind;" />
    
    <add key="Oracle_ConnectString" value=
      "Data Source=ORCL;User Id=ADODOTNETCOOKBOOK;Password=password;" />
    <add key="Oracle_Scott_ConnectString" value=
      "Data Source=ORCL;User Id=scott;Password=tiger;" />
    
    <add key="Odbc_ConnectString" value=
      "DRIVER={SQL Server};SERVER=(local);UID=sa;PWD=;DATABASE=Northwind;" />
    
    <add key="MsAccess_ConnectString" value="Provider=Microsoft.Jet.OLEDB.4.0;
      Data Source=c:\\AdoDotNetCookbook\\DB\\MsAccess\\Northwind.mdb;" />
    <add key="MsAccess_Secure_ConnectString"
      value="Provider=Microsoft.Jet.OLEDB.4.0;
      Data Source=c:\\AdoDotNetCookbook\\DB\\MsAccess\\NorthwindPassword.mdb;" />
    <add key="MsAccess_Database_Filename"
      value="c:\\AdoDotNetCookbook\\DB\\MsAccess\\Northwind.mdb" />    
    <add key="MsAccess_SecureMdw_Filename"
      value="c:\\AdoDotNetCookbook\\DB\\MsAccess\\Northwind.mdw" />
    
    <add key="Excel_0115_ConnectString" value='Provider=Microsoft.Jet.OLEDB.4.0;
      Data Source=c:\AdoDotNetCookbook\CS\Chapter01\Categories.xls;
      Extended Properties="Excel 8.0;HDR=YES";' />
    
    <add key="TextFile_0119_ConnectString"
      value='Provider=Microsoft.Jet.OLEDB.4.0;
      Data Source=c:\AdoDotNetCookbook\CS\Chapter 01\;
      Extended Properties="text;HDR=yes;FMT=Delimited";' />
  </appSettings>
</configuration>
    [ Team LiB ] Previous Section Next Section