making windows services configurable
-
I wrote a windows service in VB .NET that primarily get information from a database and does the appropriate actions. It starts up automatically on boot. The problem is that I need to make this windows service configurable e.g. The database location might be changed and I need to have a way for the service to know that. Any suggestions??
-
I wrote a windows service in VB .NET that primarily get information from a database and does the appropriate actions. It starts up automatically on boot. The problem is that I need to make this windows service configurable e.g. The database location might be changed and I need to have a way for the service to know that. Any suggestions??
I've done this using a configuration file, and if you don't like it, you can use the registry. Free your mind...
-
I wrote a windows service in VB .NET that primarily get information from a database and does the appropriate actions. It starts up automatically on boot. The problem is that I need to make this windows service configurable e.g. The database location might be changed and I need to have a way for the service to know that. Any suggestions??
You can add an entry in the web.config file in the tag. eg. You can than read this entry using ConfigurationSettings.AppSettings("keyname")
-
You can add an entry in the web.config file in the tag. eg. You can than read this entry using ConfigurationSettings.AppSettings("keyname")
I think you mean the app.config file. web.config is just for ASP.NET applications. Anyway, for the original poster... In visual studio make sure the project of your windows service has an app.config file, you use it just like the web.config file (see Pratik Desai's post above). When you deploy your application Visual Studio will change the name from app.config to myWindowsService.exe.config or whatever the exe file is called + .config. I have a feeling that the config file is only read once (I'm not sure if you can force it to re-read it to check for changes if it is only read once) in which case your service will have to be restarted. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
-
I think you mean the app.config file. web.config is just for ASP.NET applications. Anyway, for the original poster... In visual studio make sure the project of your windows service has an app.config file, you use it just like the web.config file (see Pratik Desai's post above). When you deploy your application Visual Studio will change the name from app.config to myWindowsService.exe.config or whatever the exe file is called + .config. I have a feeling that the config file is only read once (I'm not sure if you can force it to re-read it to check for changes if it is only read once) in which case your service will have to be restarted. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
So whenever I want to deploy the windows service, I have to copy the app.config file with it? If the app.config file is all I have to modify, restarting the windows service isnt really a hassle. Thanx
-
So whenever I want to deploy the windows service, I have to copy the app.config file with it? If the app.config file is all I have to modify, restarting the windows service isnt really a hassle. Thanx
Yes, but remember that when you build your application windows will copy the app.config into your Debug or Release folder and rename it with the name of the exe with the addition of the .config. Also - And it took me a while to figure out why it wasn't working the way I expected - The config file is not read while the windows service is installing. So your installer class can't access it without a lot of extra work. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)