Web variable configuration

Source: Internet
Author: User

Web variable configuration

About web variable configuration

When webservice interfaces are completed
Considering that interfaces may be used on different servers and databases
Therefore, it is easier to modify the link address to a variable in webconfig.

Access data in different databases on the same server
You can declare the database name as a variable.
Enter the Database Name and retrieve the required data based on other conditions.

According to the problem above, the following problem is extended.
When using the same interface on different servers, you need to declare the server address, database Logon account, and logon password in the interface as variables, however, you do not need to enter in the web, but modify it in webconfig. This allows you to quickly modify it, and avoids the difficulties that no one can start using interfaces.

Specific illustration:

The address of the server marked in green, the database name in red, the account used to log on to the database in blue, and the logon password in blue.

The above is not declared as a variable, only the database name is declared, is the first case

The above is the general configuration item of the connected database in webconfig. catalog is the database name, data is the server address, id is the account, and password is the password.

The name in is the name of a general tag. In other cs classes. configuration. configurationManager. connectionStrings ["SQLPublicDataBase"]. toString (); to retrieve the configuration file you named, to select which one to read

The database of the server.

 

Note: The following shows the demo status. All are named in Chinese !!!!!

Configuration in config
<Deleetask>
<Add key = "server address" value = "111.111.111.11"/>
<Add key = "database Logon account" value = "sa"/>
<Add key = "password for database Logon" value = "123456"/>
<Add key = "Database Name" value = "admin"/>
</AppSettings>


Reading in cs class
// Obtain the value in config in step 1
Public static int aaa = int. Parse (ConfigurationManager. etettings ["server address"]);
Public static int bbb = int. Parse (ConfigurationManager. deleetmanager ["database Logon account"]);
Public static int ccc = int. Parse (ConfigurationManager. etettings ["database logon password"]);
Public static int ddd = int. Parse (ConfigurationManager. etettings ["Database Name"]);

// Concatenate the connection string in step 2
String connectionString = "server =" + aaa + "; database =" + ddd + "; uid =" + bbb + "; pwd =" + ccc + "";

Related Article

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.