Web. config:
< Configuration >
< Appsettings >
< Add key = " Sqlconn " Value = " Server = localhost; database = data; uid = sa; Pwd = sa " />
</ Appsettings >
< Connectionstrings >
< Add name = " Dataconnectionstring " Connectionstring = " Data Source = localhost; initial catalog = data; user id = sa; Password = sa " Providername = " System. Data. sqlclient " />
</ Connectionstrings >
</ Configuration >
Note:
(1) appsonstrins are commonly used in 2003 and connectionstrins are commonly used in 2005.
(2) advantages of using connectionstring:
First, you can encrypt the connection string by using an encryption tool of Ms.
Second, data source controls that can be directly attached without having to writeCodeRead it and assign it to the control.
Third, you can easily change the database platform. For example, if you change to an Oracle database, you only need to modify the providername.
(3) used in <etettings>System. configuration. configurationmanager. receivettings ["name"]Search value.
Used in <connectionstrings>System. configuration. configurationmanager. connectionstrings ["name"]Search value.