473,396 Members | 1,805 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,396 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 1557
"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.