The encapsulation of the link string that accesses the database (MS everything in the package, get us the original Yue (weak) (wisdom)), well, you can explain that can easily change the link to change the configuration, without moving the main program------Isolation (isolation-protection; You should be familiar with power distribution)
I still trust the two properties of MSDN first ConfigurationManager class, two properties can achieve the goal
Example above
AppSettings:
<?xml version="1.0" encoding="utf-8" ?>< configuration> <configSections> </configSections> <appSettings> <add key="CarManager.Properties.Settings.DataConnectionString" value ="Data source=rtdz-006;initial catalog=data; User ID=TTNZ; password=12345" /> </appSettings></configuration>
Link
New SqlConnection (configurationmanager.appsettings[0]. ToString ());
————————————————————————————————
ConnectionStrings
<?xml version="1.0" encoding="utf-8" ?>< configuration> <connectionStrings> <add name="myconn" connectionstring="Data source=.;i Nitial Catalog=northwind; Persist Security info=true; User Id=sa; password="/> </connectionStrings></configuration>
Link
string connstr = configurationmanager.connectionstrings["myconn"]. ConnectionString;
————————————————————————————————————
Note: using System.Configuration; to add
Reference to add System.Configuration
Description of the App. Config app