Now, my friends who are a little familiar with Asp.net are used to writing database connection configurations to the Web. config. the configuration in the database in config is as follows:
1 <deleetask>
2 <add key = "connstring" value = "User ID = sa; Password = sasasa; Data Source = (local); initial catalog = 51 aspx"/>
3 </appsettings>
Vs built-in SQL:
<Add key = "sqlcon" value = "Data Source =. \ sqlexpress; attachdbfilename = | datadirectory | \ webzone. MDF; Integrated Security = true; user instance = true"/>
. CS File Usage:
String strconn = configurationmanager. receivettings ["connstring"];
To read, it is worth noting that: this is the read method of ASP. net2.0, in 1.1 is
String strconn = configurationsettings. receivettings ["connstring"];
Many friends may have encountered the prompt "connectionstring attribute has not been initialized". The root cause is that the key value cannot be read. The solution is to correct connstring.
Today, I also encountered the prompt "connectionstring property has not been initialized", and I cannot read the key value in Web. config.
The final reason is that I have established the http: // localhost/test virtual directory. By default, the web in the site http: // localhost is read. config value, which does not have this key at all. Set test as a site (re-create a site to test or point http: // locanhost to test, I hope you can wake up and avoid detours!