Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I'm an intermediate programmer. I just desperately need assistance as to how to create a Windows Service. I have read several articles on services but none of them seem to explain anything on DB connection as well so just posting this question here so any of you gurus can assist.

I have several files on a sever location. The service will connect to the DB and check if the spcified file has been processed already or not, it if is then it will not be processed. Otherwise the file will be processed by moving it to a new location and inserting the file names and the date processed into a table on the MS SQL Server DB.

Note that my DB connection is doen via a config file.

Actually I have a working program where every time a user is clicking a button on a form to do the processing (Windows Form program is in existence). I just want to eliminate this and have the Windows Service process it automatically.

Please assist with this as to how I can create the windows service.

Thanking you in advance.
Posted
Updated 1-Jul-13 15:35pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Jul-13 21:44pm    
Sorry, not a question. It's not clear what kind of help do you need; your concerns are not certain enough to make a valid question.

I think your mistake is looking for some tutorial on Windows Services with database. Instead, learn Windows Services separately, ADO.NET separately. Learn to separate concerns.

—SA

1 solution

Hope this helps.

In Visual Studio you have a project that automatically creates a Windows Service Project for you.

On Creating this, you will get a class in the project with the name service1.

In this there will be methods like OnStart and OnStop.

What you do is create a thread or a timer to keep repeating the process the you are currently doing by clicking a button.

In case of thread, you will need to create a loop for repeating the process, but do not forget to use Sleep function in thread after each loop.

In case of timer it will be automatically called after specified interval.

Initialize and start the thread or timer in OnStart event.

Put the last line in OnStart event as Application.Run, to keep the service running, else it will stop if it has nothing to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900