首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

在web.config配置了数据库连接,可他在.NET中如何连上呢

2012-01-23 
在web.config配置了数据库连接,可他在.NET中怎么连上呢?web.config中: appSettingsaddkey sqlConnect

在web.config配置了数据库连接,可他在.NET中怎么连上呢?
web.config中: <appSettings>
<add   key= "sqlConnection "   value= "Persist   Security   Info=False;Data   Source=127.0.0.1\NEWS;Initial   Catalog=NEWS;User   ID=sa;Password=; "   />


    </appSettings>  


string   sql= "select   *   from   Log   ";
SqlConnection   conn=new   SqlConnection( "server=user65;uid=sa;pwd=;database=NEWS ");[每调用一次要写一次,太烦了,加到CONFIG里该怎么写呢?]
conn.Open();
SqlCommand   com=new   SqlCommand(sql,conn);

ShowLog.DataSource=com.ExecuteReader();
ShowLog.DataBind();
conn.Close();

[解决办法]
string SQLConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get( "sqlConnection "));

热点排行