473,324 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 1554
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Usman | last post by:
Hi I have a window service written in C#. I have another application that requires a lengthy process to be performed like taking backup. How can I make this lengthy process be performed by...
4
by: utkarsh | last post by:
Hi, I want to develop a Window Service in C# that should be capable of sisplaying the a icon in the window tray. Based on some logic in service, icon should be changed to some other...
4
by: drodrig | last post by:
Hi. I am trying to close/kill all processes that show visible windows on Windows XP. So far I've created a script that uses win32gui.EnumWindows to iterate through all windows, check for which...
4
by: ianyian | last post by:
hi experts, im doing some staff bween th the aspx + MS Word.chellcheck, and and which running on my ypc is no problem ( windows xp , activation by ASPNET ), buts someshow when i try to deploy to...
1
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have created a very simple window service. This window service in turn is calling a function that exist in a windows form. When I am trying to run this windows service. window...
7
by: =?Utf-8?B?Vmlua2k=?= | last post by:
public void sendKeysTest() { Process myProcess = Process.Start(@"C:\winnt\system32\cmd.exe"); SetForegroundWindow(myProcess.Handle); if (myProcess.Responding) SendKeys.SendWait("{ENTER}");...
2
by: =?Utf-8?B?YW5hbmQga3VtYXI=?= | last post by:
Hi, We have a requirement where windows service application XX will be deployed on two servers that is load balanced. The windows service polls the file directory and performs some logic when the...
0
by: henkya | last post by:
Language Used: C# Project Typed: Setup Project (for .NET Window Service) Hi Bump into this issue and seriously have a hunch that this is a bug in the .NET setup project. These are the scenario:...
0
by: olanger | last post by:
Let me explain the scenerio, I have a window service that has timer and OnElapsed timer event I'm calling a method. This method process business logic and It's multi threaded. The problem...when the...
2
by: gray d newbie | last post by:
Greetings All, This is my first time creating a Window Service and I am having this error message when I try to start my window service (currently known as Service1). Below is my code for Window...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.