关闭

System.Configuration.ConfigurationManager.AppSettings["connString"];

标签: stringserver.net
3058人阅读 评论(2) 收藏 举报
分类:

在.net1.1 string strConnection = System.Configuration.ConfigurationSettings.AppSettings["connString"]; 在.net2.0 VS2005提示 警告: “System.Configuration.ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!

 解决方法 string strConnection = System.Configuration.ConfigurationManager.AppSettings["connString"];

对应的web.config设置为:

<appSettings>
    <add key ="connString" value ="server=(local);uid=sa;pwd=sa;database=testDataBase;"/>
  </appSettings>

另一种方法是:

        ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings["hello"];
        string cn = cs.ConnectionString;

对应的web.config设置为:

 <connectionStrings>
  <add name ="hello" connectionString ="server=(local);uid=sa;pwd=sa;database=testDataBase" providerName ="System.Data.SqlClient"/> 
</connectionStrings>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:24047次
    • 积分:467
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:4篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论