VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 814|回复: 1

在web.config配置了数据库连接,可他在.NET中怎么连上呢?

[复制链接]

1

主题

2

帖子

3.00

积分

新手上路

Rank: 1

积分
3.00
发表于 2020-3-13 12:00:01 | 显示全部楼层 |阅读模式
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();
回复

使用道具 举报

0

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-6-10 22:15:01 | 显示全部楼层
string SQLConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("sqlConnection"));
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表