【发布时间】:2014-08-24 13:07:47
【问题描述】:
我正在制作 Windows 服务。 它包含一个 App.config 文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SQLConnectionStr" value="Data Source=192.168.1.116;Initial Catalog=Conezone;User Id=sa;Password=saadmin@123;"/>
<add key="FilePath" value="D:\Autoparts Guru\LINES2\"/>
</appSettings>
</configuration>
为了在服务代码中获取 FilePath 值,我正在编写
ConfigurationManager.AppSettings["FilePath"].ToString()
但它会产生 NullReferenceException。
希望我能尽快得到答案。
【问题讨论】:
-
您是否尝试将 App.config 重命名为 web.config?我不确定 web 应用程序中默认情况下是否正确处理了 app.config。
-
您是否有权访问 SQLConnectionStr?
-
@Anton OP 正在谈论 Windows 服务。
-
您制作的 exe 本身是否注册为服务,或者您是否通过服务运行您的 exe?
-
@CodeCaster 对,我的错。也许这篇文章可以提供帮助:stackoverflow.com/questions/439334/…
标签: c#