Windows服务中的App.config [英] App.config in Windows Service

查看:420
本文介绍了Windows服务中的App.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在尝试读取App.Config文件中的连接字符串时,出现错误,例如对象引用未设置为对象的实例."
string strconn = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();

对于Windows服务,我需要保留app.config文件以及操作方法.

预先感谢.

Hi,
While I''m trying to read connection string which is in App.Config file I''m getting error like "Object reference not set to an instance of an object."
string strconn = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();

For the windows service where I need to keep app.config file and how.

Thanks in advance.

推荐答案



右键单击App.Config,然后
Properties > Copy to Output Directory > Copy always

然后重建项目并运行项目

我认为它会起作用
Hi,

Right click on App.Config then
Properties > Copy to Output Directory > Copy always

Then Rebuild the project and run the project

I think it will work


这篇关于Windows服务中的App.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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