VB.net configuration file

Source: Internet
Author: User
Overview

The configuration file is a file installed on the computer along with the installer, which stores the parameters required when the installed application is running. You can open the configuration file and modify the parameters, in this way, you can achieve a certain purpose without modifying the code. For example, we can change the character used to connect the configuration file to the SQL Server database to the character used to connect to the Oracle database. In this way, if the application has compiled the Oracle database code during development, then the program can run normally when the Oracle database is running.


Configuration File addition 1. To which layer?

In the overview, it is explained that the configuration file and the installed application must exist on the computer that is installed at the same time to make full use of it. Therefore, you must add the configuration file to the interface layer when adding the configuration file, if it is added elsewhere, an error occurs.


2. How to add?



Configuration File Usage 1. How to modify the configuration file

The configuration file has its corresponding writing format. As long as we write the file in the corresponding format, the key name is connstr, and the key value is the equal sign content after the value, you only need to use connstr for use.

<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <! -- Start of the configuration file --> <! -- The added node is used to modify the database connection --> <appsettings> <! -- The IP address, username, and password are your own. For example, <add key = "connstr" value = "Data Source = 192.168.27.27; initial catalog = charge; user id = admin; Pwd = abcedef "> </Add> </appsetdef> <! -- Other nodes can be added below --> </configuration> <! -- End of configuration file -->

2. How to Use the content in the configuration file

Add this reference to the project using the configuration file: system. configuration, as shown in figure

 


3. Retrieve the configuration file code

Dim strconnection as string = configurationmanager. receivettings ("connstr") 'can be used in the following method, but the 'dim connstr as string = configurationsettings. receivettings ("connstr ")

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.