We all know that the BS program can be set by the configuration file database information, the program through the reading configuration file can get the corresponding database connection string, in fact, CS program can also do so, in the project root directory of the new configuration File App. Config file, in the add configuration information, such as:
<?XML version= "1.0" encoding= "Utf-8"?><Configuration> <appSettings> <AddKey= "Dbreader"value= "server=127.0.0.1;uid=***;p wd=***;d atabase=***; Max Pool size=300; " /> </appSettings></Configuration>
In this case, the configuration file can be read in the background,
string conn = system.configuration.configurationsettings.appsettings["dbreader" ];
In order not to use system.configuration.configurationsettings.appsettings["Dbreader" every time to get configuration information, we can write a method to get the configuration information
Public Static string Get (string key) { return System.configuration.configurationsettings.appsettings[key]; }
When we call this method, we get the configuration information through the Get () method.
string connstr = Config.get ("dbreader");
Config is a class library, so we get the information on the configuration file.
WinForm Program Connection Database