日期:2014-05-17  浏览次数:20494 次

|zyciis| C#的Windows服务中的配置文件应该怎么来存放呢
如我做了一个Windows服务
本来他是一个WinForm程序
然后在程序的同一目录有set.inf来对这个程序的初始信息进行定义
如数据库链接等
那现在转为Windows服务,那这些信息要怎么来配置最好
谢谢

------解决方案--------------------
添加app.config
------解决方案--------------------
XML code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="xxxx" value="......"/>
  </appSettings>
  
  <connectionStrings>
    <add name="xxxxxx" connectionString="Data Source=xxxxxx;Initial Catalog=DB;User ID=sa;Password=" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  
</configuration>

------解决方案--------------------
探讨
添加app.config

------解决方案--------------------
读取时还都是老样子
ConfigurationManager.ConnectionStrings["xxxxxx"].ConnectionString
------解决方案--------------------
http://www.cnblogs.com/cococ/archive/2008/10/20/1315455.html
------解决方案--------------------
http://zzk.cnblogs.com/s?w=app.config&t=
------解决方案--------------------
appconfig,直接用

C# code
global::xxx.Properties.Settings.Default.xxx

------解决方案--------------------
获取<appSettings>中键的方法:
System.Configuration.ConfigurationManager.AppSettings["应用程序设置键名"]
获取<connectionStrings>中连接串的方法:
System.Configuration.ConfigurationManager.ConnectionStrings["连接串名"].ConnectionString
------解决方案--------------------
友情支持 up