Web.config和App.config配置连接字符串

读取配置文件,获取连接字符串

<!-- 第一种 -->
<connectionStrings>
    <add name="connString" connectionString="server=.;uid=sa; pwd=123456; database=SchoolDB;"/>
</connectionStrings>
<!-- string connString = System.Configuration.ConfigurationManager.ConnectionStrings["connString"].ToString(); -->

<!-- 第二种 -->
<appSettings>
    <add key="connString" value="server=.;uid=sa; pwd=123456; database=SchoolDB;"/>
</appSettings>
<!-- string connString = System.Configuration.ConfigurationManager.AppSettings["connString"]; -->

 

posted @ 2019-10-16 10:57  智者见智  阅读(429)  评论(0编辑  收藏  举报