We put the data connection string in the configuration file, but how to read it was previously used in vs2003
Configurationsettings. deleettings ["connectionstring"]. tostring ();
To read the configured connection, but the compiler prompts in vs2005:
Warning "system. configuration. configurationsettings. deleettings" is out of date:
"This method is obsolete, it has been replaced by system. Configuration!
System. configuration. configurationmanager. deleetmanager ".
So I want to find the configurationmanager class. The result is that I have referenced system. Configuration and cannot find it,
Later, I found out that the system. configuration. dll file must be added to the reference.
Sure enough, you can use the following statement to read the configuration after adding it:
System. configuration. configurationmanager. connectionstrings ["connectionstring"]. tostring ();
However, if you do not add a reference to the system. Configuraton. dll file, you can use the following method to read the data connection string in the configuration.
First, paste the content of my app. config file:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Configuration>
<ConfigSections>
</ConfigSections>
<ConnectionStrings>
<! -- Here we add an oracle data connection string -->
<Add name = "TestAdoNet2.Properties. Settings. ConnectionString"
ConnectionString = "Data Source = gz; Persist Security Info = True; User ID = gzmes; Password = gzmes; Unicode = True"
ProviderName = "System. Data. OracleClient"/>
<! -- Here we add an SQL data connection string -->
<Add name = "TestAdoNet2.Properties. Settings. NorthwindConnectionString"
ConnectionString = "Data Source =. \ SQLExpress; Initial Catalog = Northwind; Integrated Security = True"
ProviderName = "System. Data. SqlClient"/>
</ConnectionStrings>
</Configuration>
The code for getting the connection string is as follows:
// Oracle
String conn1 = Properties. Settings. Default. ConnectionString;
// SQL
String conn2 = Properties. Settings. Default. NorthwindConnectionString;