window service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • naveen babu

    window service



    hi,
    i have built a window service to send an email alert..

    when i start the service..i get the following msg

    The ScheduleAlert service on Local Computer started and then stopped.
    Some services stop automatically if they have no work to do, for example
    the Performance Logs and Alerts service.

    when i check my event log i have teh following error msg

    Service cannot be started. System.InvalidC astException: Specified cast
    is not valid.
    at ScheduleAlert.S cheduleAlert.On Start(String[] args)
    at System.ServiceP rocess.ServiceB ase.ServiceQueu edMainCallback( Object
    state)

    any help would be appreciated.

    i am getting the email....but the service is stopped


    *** Sent via Developersdex http://www.developersdex.com ***
  • Alberto Poblacion

    #2
    Re: window service

    "naveen babu" <sk_naveen2k@ya hoo.co.inwrote in message
    news:O5IbUlTDJH A.3268@TK2MSFTN GP03.phx.gbl...
    i have built a window service to send an email alert..
    >
    when i start the service..i get the following msg
    >
    The ScheduleAlert service on Local Computer started and then stopped.
    Some services stop automatically if they have no work to do, for example
    the Performance Logs and Alerts service.
    >
    when i check my event log i have teh following error msg
    >
    Service cannot be started. System.InvalidC astException: Specified cast
    is not valid.
    at ScheduleAlert.S cheduleAlert.On Start(String[] args)
    at System.ServiceP rocess.ServiceB ase.ServiceQueu edMainCallback( Object
    state)
    >
    any help would be appreciated.
    >
    i am getting the email....but the service is stopped
    Well, the event log is quite clear. You have a mistake in your OnStart
    method: It is performing an invalid cast. Since you get the email, the error
    is somewhere in your code below the part that sends the message.


    Comment

    • csharp 22

      #3
      Re: window service



      hi,
      tnx for your reply...as i said i am pretty new to windows service
      ...this is my first one

      can you plz guide me where the error is ....this is my onstart event

      protected override void OnStart(string[] args)
      {
      // TODO: Add code here to start your service.
      SqlConnection stCon = new SqlConnection(" Data
      Source=.;Initia l Catalog=abcd;Us er ID=sa;Password = abcd");
      SqlDataAdapter da = new SqlDataAdapter( "select * from
      ActionItems", stCon);
      DataSet ds = new DataSet();
      da.Fill(ds);
      foreach (DataRow dr in ds.Tables[0].Rows)
      {
      DateTime dueDate = (DateTime)dr["Action_Duedate "];
      DateTime now = DateTime.Now;
      if((dueDate.Day == now.Day) && (dueDate.Month ==
      now.Month) && (dueDate.Year == now.Year))
      {
      sendMail(dr);
      }
      }
      ServiceControll er[] services =
      ServiceControll er.GetServices( );
      foreach (ServiceControl ler x in services)
      {
      if (x.DisplayName == "ScheduleAlert" )
      {
      if (x.Status ==
      System.ServiceP rocess.ServiceC ontrollerStatus .Running)
      {
      x.Stop();
      }
      else
      {
      x.Start();
      }
      }
      }
      }


      thank you once again

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • Alberto Poblacion

        #4
        Re: window service

        "csharp 22" <sk_naveen2k@ya hoo.co.inwrote in message
        news:e6aDSDeDJH A.1628@TK2MSFTN GP02.phx.gbl...
        can you plz guide me where the error is ....this is my onstart event
        I don't see anything in that code that could throw an "Invalid cast"
        after executing sendMail(dr). Maybe the error is inside the sendMail
        subroutine, which you must have written elsewhere?
        You could experiment surrounding that line with a try..catch to find out
        if it is indeed throwing an exception. Or you could connect the debugger to
        the Service (do an internet search for this, there are plenty of documents
        explaining how to do it) and execute your code step by step to find the
        problem.


        Comment

        Working...