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 + "";