setting a connection string for a Windows Service on production

B

Bill Mild

Feel free to let me know if there is a better place to post this question

I'm a website developer trying to write a Windows Service, and I think I'm
running into trouble due to the paradigm shift.

In website development, I change the web.config file on the fly without
re-building a project. How does this work with the app.config in a Windows
Service? It seems like when I update a ConnectionString in app.config after
rolling to a production server, it doesn't take. Does app.config get
complied into the executable on build so that I can't change it on the fly?
If so, how would I set it up to be able to configure the db connection string
on the production server?

Thanks.
 
N

Norman Yuan

It depends on how the WIN Service app reads the connectionString from
app.config. If you let the service read app.config at startup only, then you
need to stop and restart the service once the app.config is changed. This is
the common approach. As the developer of the Service, you do know when the
service app reads the settings in app.config, don't you? The best thing to
do is to make sure the ConnectioNString is correct before installing the Win
service in a production box.

If for some reasons that your service can never be stopped once started,
then you could code the service to read the ConnectionString setting in
app.config periodically to see if change has been made, if yes, use the
newly read ConnectionString. However, I doubt its necessity, although it is
technically doable.
 
B

Bill Mild

Thanks Norman. You basically told me that when I stop and restart the
service, it should re-read the app.config at that point. That is what I
would have expected. There must be something deeper going on. Due to time
constraints, I've opened a case with Microsoft to get this figured out.

Thanks Again,
Bill
 
J

John Vottero

Bill Mild said:
Thanks Norman. You basically told me that when I stop and restart the
service, it should re-read the app.config at that point. That is what I
would have expected. There must be something deeper going on. Due to
time
constraints, I've opened a case with Microsoft to get this figured out.

One key difference between app.config and web.config is that app.config gets
renamed to yourprogram.exe.config and copied to the build output directory.
Is that the file that you're changing?
 
B

Bill Mild

John,

That was exactly the problem. I was changing the app.config in root of the
project, instead of *.exe.config in the release folder.

Thanks,
Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top