473,218 Members | 1,783 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,218 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 1547
"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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.