当前位置: 代码迷 >> ASP.NET >> 请教webconfig连接数据库
  详细解决方案

请教webconfig连接数据库

热度:7414   发布时间:2013-02-25 00:00:00.0
请问webconfig连接数据库
比如我在webconfig里配置 
  <appSettings > 
  <add key="DSN" value="server=ADMIN;uid=sa;pwd=35144315;database=ms"/ > 
  <add key="bgColor" value="blue"/ > 
  </appSettings >
 
调用 
string conn2 = System.Configuration.ConfigurationSettings.AppSettings["DSN"];

警告 1 “System.Configuration.ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings” C:\Documents and Settings\Administrator\桌面1\Default.aspx.cs 20 28 C:\...\桌面1\

请问怎么实现和
SqlConnection conn=new SqlConnection("server=ADMIN;uid=sa;pwd=35144315;database=ms"); 
conn.open; 
一样的效果? 谢谢


------解决方案--------------------------------------------------------
这样引用就不过时了
System.Configuration.ConfigurationManager.AppSettings["DSN"];