2010-07-28 44 views
2

我看到一個非常不錯的文章在這裏約我想要做什麼,ConfigurationManager - 如何在.NET 3.5中使用連接字符串?

.net 3.5: To read connectionstring from app.config?

它說,使用ConfigurationManager中類。我無法引用ConfigurationManager類。

如果我看看我正在使用的system.dll(這是v2.0.50727),沒有ConfigurationManager類。

我使用VS 2008,我的項目設置爲.NET 3.5編譯。

如果我這樣做,

string test = System.Configuration.ConfigurationManager.AppSettings["test"]; 

我得到的消息「錯誤182的類型或命名空間名稱ConfigurationManager中System.Configuration‘'不存在命名空間存在’(是否缺少程序集引用? )'

任何想法?

+0

已添加到System.Configuration參考? – richeym 2010-07-28 22:59:34

+0

對。我以爲我有,但我引用'System'dll – peter 2010-07-28 23:00:43

回答

8

ConfigurationManagerSystem.Configuration命名空間的一部分。默認情況下,它並未在項目中引用,因此請添加對來自GAC的if的引用。

+0

Yep中的命名空間'System.Configuration',正如我上面提到的,我引用了'System'dll中的命名空間'System.Configuration' – peter 2010-07-28 23:03:32

1

您對參考文件夾參考「system.configuration.dll」

僅需右擊VS,搜索這個dll