"VB. NET room Reconfiguration "--Brief description of configuration files

Source: Internet
Author: User
Tags connectionstrings

Computer room fee system reconstruction, see a lot of information about reflection + configuration file, I do not know what, how to use, but a lot of predecessors have gone through, with this thing, of course, they have to try, and then after the inquiry and discussion, the knowledge of the parties to summarize and organize, plus their own a little understanding , leave this blog post.

1. What is it, what can I do?

The configuration file is a standard XML file, and XML tags and attributes are case-sensitive. Installed with the installer to a file on your computer that contains the parameters needed to run the installed application, it can change the parameters as needed, and the developer can use the configuration file to change the settings without recompiling the application. The root node of the profile is the configuration file.

2. Benefits?

Definitions are often dull things, and any definition seems to be laborious, and when we understand it from other aspects, we look back at the definition and feel that we are saying it well, and that is the case; we should look at his benefits and be helpful in understanding the configuration file. Computer room charge system we need to connect to the database, if we add the database connection character to the configuration file, specify a variable to represent the character, then in the program used, we use this variable name, when changing the configuration file character, all the contents of the system will change. Just like constants, the const double pi =3.14. All pi in the program is 3.14 this value, if you want to modify the value of all the pi in the program, only need to define the changes in the line. Increases the robustness of the system.

in the machine room also through the configuration file, modify the database corresponding to the system. To change the database character of SQL Server in the configuration file to access database, the code that operates the two kinds of databases is written separately in the system. Then the program can be easily replaced in two data between the use.   

3. Where should I add it?

In the program 7 layers each layer has the configuration file, then where should add? Just beginning to see the predecessors have filled the UI layer, why? It is understood that because the UI layer is the startup item for the entire program, it is executed first, then its configuration file is compiled, and the configuration file content is used later in the system. Some people say this: The configuration file needs to be added to the main assembly (that is, the form application or other application that was generated when the project was originally created). After compilation, it is generated in the same directory as the application (. exe file). If you do not see the XXX.exe.config file in the home directory of the compiler, then you are probably not adding to the place.

4. What is the format of the code? The format of the comment?

So here you open the config file for the U-layer, app. Config, and add the required content inside. If the UI does not have a configuration file, then on the U-layer, right-click Add-to-left common items, select General, and then click application Configuration file-file suffix is. config format;

<pre name= "code" class= "HTML" ><?xml version= "1.0" encoding= "Utf-8"?><configuration> <startup&        Gt <supportedruntime version= "v4.0" sku= ". netframework,version=v4.5 "/> </startup><!--notes: Add a configuration file that can be used appsettings and connectionstrings two kinds of-->< Pre name= "code" class= "HTML" style= "FONT-SIZE:16PX; line-height:24px; " ><!--Note: To change the contents of value, you can select the database type--> with which the system operates; 
<appsettings><add key = "DB" value = "SQL Server"/></appsettings><!--Note: Database connection characters are added to the configuration file, Use connstring on the line, no longer in the program to assign value--><connectionstrings><add name = "ConnString" connectionString = "server=.; Database=jifang_sys;user id=sa;password=123456 "/></connectionstrings></configuration>

5. Use

1. Adding references

You need to use the layer of the configuration file to add a reference; Right-click on the layer to add a reference;

2. Using the configuration file

The database connection character is used in the program;

For example:

     Dim connstring as String = Configurationmanager.appsettings ("connstring")

Summary:

The benefit of the configuration file or in the continuous implementation of the system to continue to feel, the current can be realized in the database connection characters and database replacement, in fact, with the configuration file, has been in these two aspects of the work to save us a lot. Other circumstances, specifically encountered specific solutions.


"VB. NET room Reconfiguration "--Brief description of configuration files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.