类库中使用ConfigurationManager.ConnectionStrings的步骤:
一直没弄明白怎么在类库中找不到 ConfigurationManager.ConnectionStrings

后面才发现没有添加System.configuration的引用,添加后:

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

引入命名空间:
复制代码 代码如下:
  using System.Configuration;

便可以使用了:
复制代码 代码如下:
  public static string ConnectionString = ConfigurationManager.ConnectionStrings["Conn"].ToString();

接下来讲解下asp.net与数据库连接的操作方法:

 1.打开vs2010---视图----服务器资源管理器:

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

2.右击数据连接---添加连接:

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

3.找到要添加的数据库文件,添加:(登入到服务器可以默认Windows身份登入,不要用户名密码)

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

4.点击确定,就添加到了asp.net中:

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

5.接下来是建立连接:(右击属性)

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

将上面连接字符串的路径复制到web config中:

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

在代码中使用连接字符串:

asp.net中连接字符串问题(类库中使用ConfigurationManager.ConnectionStrings)

 

                                                                 鸣谢:Ya飞

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2021-07-15
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-08-13
  • 2021-08-22
  • 2022-01-15
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案