Results 1 to 9 of 9

Thread: [RESOLVED] The Config File

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] The Config File

    Should I be making more use of the config file?
    Firstly where is it, secondly what kind of stuff should I be using it for? I havent used it for anything as it sounded like I shouldnt mess with it!

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: The Config File

    To add a config file, right click your project > add new item > configuration file. I use them in nearly every project I use to keep away from hard coding data. Database connection strings are a good example of what to put in. You can also put dictionary objects in your config. Here is one of mine:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    	<configSections>
    		<section name="ReQue" type="System.Configuration.DictionarySectionHandler"/>
    	</configSections>
    	
    	<appSettings>
    			<!-- Define the Ultraedit info -->
    		<add key="UltraPath" value="\\sdn_apollo\hew\HEW_Common\Applications\ULTRAEDT10\"/>
    		<add key="UltraName" value="UEDIT32.EXE"/>
    		<add key="UltraINI" value="Fred.INI"/>
    		<add key="TempFolder" value="C:\Temp\Chase\"/>
    			<!-- Monitor ECN upload -->
    		<add key="WebServer" value="http://scs.com/files.html"/>
    			<!-- Define the BTS server settings -->
    		<add key="DefaultServer" value="Production"/>
    		<add key="Internal" value="\\intest\hew_*************\"/>
    		<add key="External" value="\\bztst\hew_*************\"/>
    		<add key="Production" value="\\btsp\hew_*************\"/>
    			<!-- Define the SQL server Settings -->
    		<add key="DBInternal" value="server=MSSQL\I;database=HTC;Integrated Security=SSPI"/>
    		<add key="DBExternal" value="server=MSSQL\E;database=HTC;Integrated Security=SSPI"/>
    		<add key="DBProduction" value="server=MSSQL\P;database=HTC;Integrated Security=SSPI"/>	
    			<!-- The following server selection is used for archive and sent older than 3 months -->
    		<add key="Previous" value="\\Sdn\hew\HEW_Common\HEW_*************\"/>
    			<!-- Output directory where reports are requeued -->
    		<add key="OutputLocation" value="\Output\"/>
    	</appSettings>
    	
    	<ReQue>
    			<!-- Keys must be unique -->
    		<add key="997" value="HTC\Archive"/>
    		<add key="TA1" value="HTC\Archive"/>
    		<add key="EFL" value="HTC\Archive"/>
    		<add key="RPT" value="HTC\Archive"/>
    		<add key=".997" value="Medicare_Only\Archive"/>
    		<add key=".TA1" value="Medicare_Only\Archive"/>
    		<add key=".EFL" value="Medicare_Only\Archive"/>
    		<add key=".RPT" value="Medicare_Only\Archive"/>
    	</ReQue>
    </configuration>

  3. #3

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: The Config File

    Thanks at least I know now where to get one from.
    I normally declare my connection string as a public read only property in a DataBase Class I create, what is the advantage of the config way? Alot of it doesnt make sense how are properties accessed? Is it mainly then just used for storing common properties?

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: The Config File

    If you declare a connection string in all your programs, whenever a database change occurs you'll have to edit, recompile, and deploy those programs. This is a way to do it dynamically. It also helps if you use different databases in test and production environments. You would have identical executables on booth servers, but a setting in the config file could be changed depending on how you need it.

  5. #5

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: The Config File

    So its a file that sits on a server and is referenced by the programs at execution time? Thus changes to the file will automatically be replicated to all reliant programs?

  6. #6
    Addicted Member
    Join Date
    Jan 2005
    Location
    Quagmire of programming
    Posts
    165

    Re: The Config File

    The config file resides in the same directory as the executable file. For example, if you called your application 'Test', then you would have a 'Test.exe.config' file located in the directory. Whenever the program starts, it checks this file for any configuration directives that it needs to pick up and applies them as necessary.

    You can also reference this file from within the program (as wild_bill was talking about) by way of the ConfigurationSettings.AppSettings method. That way, you can have settings that may change constantly in an XML file that can be easily changed instead of having to re-compile just to change one setting.

    Kyjan

  7. #7

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: [RESOLVED] The Config File

    So any change to a database connection string would still require the modified config file to be replaced on each machine on the network as the config file is stored on the client pc?

  8. #8
    Addicted Member
    Join Date
    Jan 2005
    Location
    Quagmire of programming
    Posts
    165

    Re: [RESOLVED] The Config File

    Unless you're running the program from a network share, in which case the config file is stored in that network share directory.

    Kyjan

  9. #9
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: The Config File

    Quote Originally Posted by FishGuy
    So its a file that sits on a server and is referenced by the programs at execution time? Thus changes to the file will automatically be replicated to all reliant programs?
    As far as I know you cannot share a config file between multiple programs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width