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

原创 2007年09月30日 17:25:00

在.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>

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:System.Configuration.ConfigurationManager.AppSettings["connString"];
举报原因:
原因补充:

(最多只允许输入30个字)