469,625 Members | 1,564 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

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.InvalidCastException: Specified cast
is not valid.
at ScheduleAlert.ScheduleAlert.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)

any help would be appreciated.

i am getting the email....but the service is stopped
*** Sent via Developersdex http://www.developersdex.com ***
Sep 2 '08 #1
3 1419
"naveen babu" <sk*********@yahoo.co.inwrote in message
news:O5**************@TK2MSFTNGP03.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.InvalidCastException: Specified cast
is not valid.
at ScheduleAlert.ScheduleAlert.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(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.
Sep 3 '08 #2


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=.;Initial Catalog=abcd;User 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);
}
}
ServiceController[] services =
ServiceController.GetServices();
foreach (ServiceController x in services)
{
if (x.DisplayName == "ScheduleAlert")
{
if (x.Status ==
System.ServiceProcess.ServiceControllerStatus.Runn ing)
{
x.Stop();
}
else
{
x.Start();
}
}
}
}
thank you once again

*** Sent via Developersdex http://www.developersdex.com ***
Sep 3 '08 #3
"csharp 22" <sk*********@yahoo.co.inwrote in message
news:e6**************@TK2MSFTNGP02.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.
Sep 3 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by drodrig | last post: by
1 post views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by
7 posts views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by
2 posts views Thread by =?Utf-8?B?YW5hbmQga3VtYXI=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.