Windows service run first time then stop

Last Reply 5 months ago By Mudassar

Posted 5 months ago

my window service is running only once .after that its not scheduling for next time.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using GenSQL;



namespace Udyog_Bandhu_Service
{
    public class UdyogBandhu
    {
        static string SourceConStr = ConfigurationManager.ConnectionStrings["EODBService"].ConnectionString;

        static UdyogBandhu()
        {

        }
        public void UpdatePayments()
        {
            try
            {
               
                
                DBHelper SourceDBHelper = new DBHelper(SourceConStr);

                UPSwpNiveshMitraServices.upswp_niveshmitraservicesSoapClient client = new UPSwpNiveshMitraServices.upswp_niveshmitraservicesSoapClient();

                DataTable dtPayment = SourceDBHelper.ExecuteDataTableProc("PROC_getPaymentDetails_WindowService", null);

                if (dtPayment.Rows.Count > 0)
                {

                    UdyogBandhuService.WriteToFile("Success : {0}" + dtPayment.Rows.Count);
                    foreach (DataRow item in dtPayment.Rows)
                    {
                       // DataSet ds = client.WGetUBPaymentDetails(Convert.ToString(item["Control_ID"]), Convert.ToString(item["Unit_Id"]), Convert.ToString(item["ServiceID"]), Convert.ToString(item["passsalt"]));
                        DataSet ds = client.WGetUBPaymentDetails("UPSWP170000411", "UPSWP17000041101", "SC06002", "fcf18dfd1405fbe78ff459e85e7b96");
                        if (ds != null && ds.Tables[0].Rows.Count == 1)
                        {
                            if (Convert.ToString(ds.Tables[0].Rows[0]["Status_Code"]) == "11")
                            {
                                SqlParameter[] param = new SqlParameter[]{
                                     new SqlParameter("@Control_ID",ds.Tables[0].Rows[0]["Control_ID"]),
                                     new SqlParameter("@Unit_Id",ds.Tables[0].Rows[0]["Unit_Id"]),
                                     new SqlParameter("@Service_ID",ds.Tables[0].Rows[0]["Service_ID"]),
                                     new SqlParameter("@ProcessIndustryID",ds.Tables[0].Rows[0]["ProcessIndustryID"]),
                                     new SqlParameter("@ApplicationID",ds.Tables[0].Rows[0]["ApplicationID"]),
                                     new SqlParameter("@Fee_Amount",ds.Tables[0].Rows[0]["Fee_Amount"]),
                                     new SqlParameter("@Fee_Status",ds.Tables[0].Rows[0]["Fee_Status"]),
                                     new SqlParameter("@Transaction_ID",ds.Tables[0].Rows[0]["Transaction_ID"]),
                                     new SqlParameter("@Transaction_Date",ds.Tables[0].Rows[0]["Transaction_Date"]),
                                     new SqlParameter("@Transaction_Time",ds.Tables[0].Rows[0]["Transaction_Time"]),
                                     new SqlParameter("@Transaction_DateTime",ds.Tables[0].Rows[0]["Transaction_DateTime"]),
                                     new SqlParameter("@Status_Code",ds.Tables[0].Rows[0]["Status_Code"]),
                                     new SqlParameter("@Remarks",ds.Tables[0].Rows[0]["Remarks"]),
                                 };
                                DataTable dtResult = SourceDBHelper.ExecuteDataTableProc("Proc_InsertUpdatePaymentDetails_UB_WindowService", param);
                                if (dtResult != null && dtResult.Rows.Count > 0)
                                {
                                    
                                    if (Convert.ToString(dtResult.Rows[0]["Flag"]) == "1")
                                    {
                                        UdyogBandhuService.WriteToFile("Success Message {0} " + dtResult.Rows[0]["Msg"]);
                                    }
                                    else
                                    {
                                        UdyogBandhuService.WriteToFile("Info Message {0} " + dtResult.Rows[0]["Msg"]);
                                        
                                    }
                                    UdyogBandhuService objser = new UdyogBandhuService();
                                    objser.ScheduleService();
                                }

                            }
                        }
                        else
                        {
                            UdyogBandhuService.WriteToFile("Info Message : No Record Found from Udyog Bandhu Service.");
                        }
                    }

                }
                else
                {
                    UdyogBandhuService.WriteToFile("Info Message : There is no record found to update from Database.");
                }

              
            }
            catch (Exception ex)
            {

                UdyogBandhuService.WriteToFile("ERROR AT  {0} " + ex.Message);
            }
        }

        #region WriteToFileLog

        public static void WriteLog(string log, string type)
        {

            try
            {
               

            }
            catch (Exception ex)
            {
                UdyogBandhuService.WriteToFile("ERROR AT {0} \n Log:" + log + " \n Message:" + ex.Message);
            }

        }

        #endregion
    }
}

 

 <appSettings>
    <!--<add key ="Mode" value ="DAILY"/>-->
    <add key="Mode"  value="Interval" />
    <add key="IntervalMinutes"  value="1" />
    <add key="ScheduledTime"  value="19:01:00" />
    <add key="ScheduledTimes"  value="10:00:00,10:30:00,10:45:00,11:00:00,11:15:00,11:30:00,12:30:00,15:15:00,15:45:00,16:00:00,17:00:00,17:15:00,18:00:00,19:00:00,20:00:00" />
    <add key="ErrorLogPath"   value="C:\\EODB\\ServiceLog.txt"/>
    <add key="isAllowed"   value="Y"/>

  </appSettings>

 

Posted 5 months ago

Do error logging, it may be possible your Windows service is crashing and stopping.

You can also check Windows event log.