ConfigurationManager未在c#中显示 [英] ConfigurationManager not showing in c#

查看:90
本文介绍了ConfigurationManager未在c#中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友



我已经在我的窗口表单中添加了一个配置文件,并试图通过我的按钮点击以下查询来调用它...



Dear Friends

I have add a config file to my window form and trying to calling that through my button click with following query..

SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;



但是它显示ConnectionManager的错误。我还在表单中包含Using System.Configuration。



请帮帮我,我有Vistual Studio 2010



谢谢


but it is showing Error for ConnectionManager. I have also include Using System.Configuration in form.

Please help me I have Vistual Studio 2010

Thanks

推荐答案

如果你看到这个问题并且它是编译错误,我几乎可以保证你没有添加对System.Configuration.dll的引用。很多人似乎认为配置管理器是在VS项目中默认获得的引用。



如果在解决方案资源管理器中展开引用,您应该会看到此文件丢失。要修复它,请通过右键单击References节点添加对System.configuration的引用,然后选择添加引用... 以打开引用对话框。



但是,如果它是运行时错误,我怀疑你的配置文件中没有名为 ConnectionString 的连接字符串。当您尝试从配置中获取 ConnectionString 属性时,这将导致null异常。



由方式 - 当你说你有错误时,通常最好说出错误究竟是什么。这是运行时错误吗?是编译错误吗?
If you are seeing this issue and it''s a compilation error, I can pretty much guarantee that you haven''t added the reference to System.Configuration.dll. A lot of people seem to think that the configuration manager works from the references you get by default in a VS project.

If you expand your References in the solution explorer, you should see that this file is missing. To fix it, add the reference to System.configuration by right clicking on the References node and select Add reference... to open the reference dialog.

If, however, it''s a runtime error, I would suspect that you don''t have a connection string named ConnectionString in your config file. This would result in a null exception when you tried to get the ConnectionString property from the configuration.

By the way - when you say you have an error, it''s generally a good idea to say what the error actually is. Is it a runtime error? Is it a compilation error?


如果解决方案节点在解决方案资源管理器中可见,VS2008将仅显示配置管理器。



如果您只有一个项目,解决方案将不会显示,因此您无法看到配置管理器。



要解决此问题,请确保以下选项检查。

回答:



工具|选项|项目和解决方案|一般|始终显示解决方案





该用户从DaveL的答案中获取此信息 this [ ^ ]问题。完全归功于Stack Overflow上的问题解决者。



由Peter O''Hanlon编辑回应关于海报抄袭工作的评论。
VS2008 will only show the Config manager if the solution node is visible in the Solution Explorer.

If you only have a single project, the solution will not show hence you can''t see the config manager.

To solve this, make sure the following option is checked.
answer:

Tools|Options|Projects and Solutions|General|Always Show Solution


This user took this information from DaveL''s answer to this[^] question in StackOverflow. Full credit goes to the problem solver on Stack Overflow.

Edited by Peter O''Hanlon in response to comment about poster plagiarising work.

这篇关于ConfigurationManager未在c#中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆