none
How to parse XML file through windows service and import the data from XML file to SQL server DB and schedule the package. RRS feed

  • Question

  • Developers, I am having a Complex XML file which should be parsed in the Windows Service and populate the data in the SQL Server DataBase and schedule the task daily at a particular time.Can anyone suggest me how to do this task and I need reference link with sample example with C# code to parse XML file in Windows Service and import the data into the DB with SQL Server Connection and scheduling.

    sai teja akhil madivada

    Monday, June 19, 2017 11:28 PM

All replies

  • I will give you high level advice.

    First off more likely than not you will need to start/stop the service along with enabling debugging. The screenshot below I built for just that purpose for a in house windows service where the buttons speak what they are for.

    Would share source but it's all C# yet is possible with vb.net

    In regards to debugging, you should have a utility such as above to start it. In the OnStart event the first line should be (and this should be removed for production else a crash ensues)

    Debugger.Launch

    Have Visual Studio open to that project. When you have started the service VS will prompt to debug it.

    If you are going to keep the service running Google windows services and Interval, most have Daily and by the minute.

    When looking at the timing, use a TImer with a TimerCallBack. Set the timer to the proper interval in say OnStart (I do it a bit differently).  Set the event to fire off in the Timer's callback e.g. mServiceTimer.Change(x, Timeout.Infinite) where n is the interval.

    In the dispatch event Dispose of the Timer and start it back up again. If you want I can post the C# code.

    In regards to parsing the xml and database operations, create a class (or more if needed) to process the xml and finally the data. If you can get far enough to have classes built and callable come back and tell us where you are stuck.

    See also: Google TopShelf (may be hard to find vb.net example and more likely will use the wrong Timer)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, June 19, 2017 11:49 PM
    Moderator
  • A Windows service is a continuous running program that is started and stopped. The Windows service cannot be scheduled. You can spawn a thread in a Windows service to start at a certain time and do processing.

    Maybe, you'll be better off using a Windows form or Console application that you can use the Windows Job Scheduler to schedule the job for running. 

    Tuesday, June 20, 2017 12:00 AM
  • Hi Akhil,

    I find Parsing XML file and reading XML file into dataset for your reference:

    http://www.drdobbs.com/windows/parsing-xml-files-in-net-using-c/184416669

    https://msdn.microsoft.com/en-us/library/ekw4dh3f.aspx?f=255&MSPPError=-2147217396

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 21, 2017 6:04 AM
    Moderator