When developing a program, multiple databases may be used, such as a database being used by customers and a test database. During development, I may often switch between these two databases. In the past, my approach was to modify the web.config file, but this was really inconvenient. Recently I discovered that it can be easily adjusted through preprocessor directives.
First define the connection strings of the two databases in web.config.
OracleHouseConnectionStringTest
OracleHouseConnectionString
Modify the place where you get the string as follows:
public static string OracleWaterGasConnectString
{
get
{
#if DEBUG
return Utility.GetConfig("OracleWaterGasConnectionStringTest");
#else
return Utility.GetConfig("OracleWaterGasConnectionString");
#endif
}
}
Then make the following settings to add two configurations
To adjust the database in the future, you only need to change the configuration to the right of the start button.