Application configuration file

Source: Internet
Author: User
Tags configuration settings


Here the main record in the learning process of the use of configuration files, because it is from the computer room reconfiguration contact, the computer room in the form as an example. one, where the holy.

The application configuration file contains application-specific settings. This file contains configuration settings that the common language runtime reads, such as assembly binding policies, remoting objects, and so on, and settings that the application can read. The name and location of the application configuration file depends on the application's host, and in VS, the name of the profile is an application with a. config extension. [MSDN]

Using the configuration file is because you want to thin the D layer of the three-tier architecture and use it in SqlHelper, you need to define the variable to get the connection string for the database.

The correct code is as follows

Imports system.configuration   ' Configure
Private ReadOnly connstr as String = System.Configuration.ConfigurationManager.AppSettings ("connstr") ' Gets the connection string for the database


Two, the problem 1, the ConnectionString property has not been initialized


Description: Breakpoint debugging, ConnStr for nothing, can not get the database string, may be the reason for the configuration file.

Resolve: Check the contents of the configuration file, are all written correctly. 2, ConfigurationManager is not a member of configuration

Description: ConfigurationSettings. AppSetting can be written out smoothly, but it is obsolete.

Resolution: Re-referencing System.Configuration.dll.



Then add the Imports System.Configuration in the code.



Third, summary

After solving the problem, I think it takes a little more time, but to solve the problem, to find the answer, and incidentally to understand him and some other things, very fulfilling. Once again the problem and the mistake, do not be afraid, the face always lets you see the different scenery.


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.