?
Solved

Windows service with app.config file

Posted on 2006-03-24
5
Medium Priority
?
5,561 Views
Last Modified: 2012-06-21
Hi Experts,
In my config file i have source path and destination path...
i am using these paths in my windows service to rename files...
if i use the map drives then it works but when i use 90.xxx.xxx.xx\somepath then it doesnt work.

Note i have tried to change user account to the accout that has access to the above path...

Need assistance to create a log file so i would now what error is happening and how do i resolve this. below is my config file and code from windows service to rename the destination files
CONFIG FILE
<!-- <add key="FilesPath" value="C:\DestinationFolder\" /> -->  works great with drives specified

 <add key="FilesPath" value="\\90.xxx.xxx.xx\q$\SourceFiles\" />
       
WINDOWS SERIVICE. (in short)
strfilesPath = ConfigurationSettings.AppSettings.Get("FilesPath")
stroldfilename = (here i get the file name i want to rename)
strNewFilename = stroldfilename + ".dat"
'RENAMING FILE
Rename(strfilesPath + stroldFileName, strfilesPath + newFileName)

dont knwo why it is not working when i use ip addres in my config file... can you tell me how to trap the error so i would atleat knwo it is because of the ip address i am entering or there is some problem in the service.
Note: service works file if i use Mapped drive letter
0
Comment
Question by:Junior_Developer
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 16284383
Rather than guessing, why not install the service on your development box and attach the debugger to it after the service is started.  That way you can step through it and figure out exactly what is wrong.

In general, you want a try/catch block at the top of your call stack.  If you are using a timer or filewatcher it would be that event handler.  Then in your catch block you can write out the exception description to the event log using something as simple as     Me.EventLog.WriteEntry(ex.Description)
0
 

Author Comment

by:Junior_Developer
ID: 16284730
this is great i didt not we can step through the windows service...
can you guide me a little more how would i do that.. i appreciate  it
0
 
LVL 21

Expert Comment

by:mastoo
ID: 16284783
With the service running, start your IDE, go to Tools / Debug Processes, turn on the two checkboxes to show you all processes, select your service from the list box, attach, ok and then close.

The debugger is now running on your service.  Set a breakpoint and you're set.  The only problem with this is you can't easily debug code that runs during the OnStart event because you can't attach fast enough.  If that's the case, let me know and I could explain a work-around.
0
 

Author Comment

by:Junior_Developer
ID: 16284870
Thanks but i would like to know the work around as my code is in onStart()

0
 
LVL 21

Accepted Solution

by:
mastoo earned 2000 total points
ID: 16284908
Windows only waits 30 or 60 seconds for a response from OnStart, so it isn't practical to step through OnStart in a debugger.  I just add a System.Timers.Timer using a short delay and autoreset=false, and then enable the timer in the OnStart.  Then move your OnStart code to be in the timer_elapsed handler.  Add a line at the beginning of the timer_elapsed handler to do a System.Threading.Thread.Sleep( 60000 ), and now when you start the service you have 60 seconds to attach the debugger to your process and set a breakpoint right after the sleep call.

After your done just comment out the sleep.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question