获取C#配置文件中的 数据库连接字符串 问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 10:10:43
我使用System.Configuration.ConfigurationSettings.AppSettings["connStr"];语句,提示这样的用法已过时.
这样我应该使用什么语句呢?
三楼说的是:System.Configuration.ConfigurationManager.AppSettings["connStr"]吗?

我试过在System.Configuration加一点(.),但在自动显示的下拉框里没有ConfigurationManager一项。
是不是我没有引用什么命名空间?

添加了using System.Configuration; 也不行。说明一下我用的是vs 2005。

我引用的命名空间跟你的一样啊,为什么我的就不行呢。

我查了http://msdn.microsoft.com/zh-cn/downloads/system.configuration.aspx,发现在System.Configuration下的确存在ConfigurationManager。
而且在 http://msdn.microsoft.com/zh-cn/downloads/system.configuration.configurationsettings.aspx下有这样的说明:“ConfigurationSettings 类仅提供向后兼容性。对于新的应用程序,应改为使用 ConfigurationManager 类或 WebConfigurationMana

用ConfigurationManager.AppSettings["connStr"]试试

完整的是System.Configuration.ConfigurationManager.AppSettings["connStr"]

可能要引用下using System.Configuration;

我也用2005的 我那个文件里所有引用的空间是:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

之后就能直接用ConfigurationManager.AppSettings了

如果你创建的是项目的话要在引用文件夹右击点添加引用 然后把System.Configuration添加进来就行了

你右击添加引用试试

System.Configuration.ConfigurationSettings.AppSettings["connStr"].ToString();

过时的东西还是可以用的啊~~~