在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 "));