在web.config 中输入 ConnectionString 避免每次连接数据库都要写 ConnectionString

web.config

<configuration>

<appSettings>
  <add key="DBConnectionString" value="server=localhost;database=web;uid=sa; pwd="/>
 </appSettings>
</configuration>

----------------------------------------------------------------------------------------------------------

xxx.aspx.cs

SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]);

原文地址:https://www.cnblogs.com/no7dw/p/1515199.html