473,671 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows service not reading sql table

Hi,
I have created a windows service which is responsible for running
certain tasks when they are scheduled to run. The service monitors a sql
table and runs a task when the task scheduled time is overdue. This service
is installed at several sites and on 4 out of 5 sites runs the tasks
correctly on schedule. However on some other sites the task will run one
night but then not run the next night and not subsequent nights. If i stop
and start the service on these sites the tasks run immediately. I am also
logging any error messages to the event log and i receive no errors on these
sites. The timer event occurs every 10 seconds.

1/Is setting objects to null the correct way to tell the GC that the object
is ready for Garbage collection?
2/Any ideas on why the service appears not to be reading the table under
some circumstances.
private static void Timer_Elapsed(o bject sender,
System.Timers.E lapsedEventArgs e)

{

// Poll epossync schedules table for jobs.

Timer.Enabled = false;

SQL.SqlDataRead er DR = null;

try

{

if (DR != null)

{

DR.Close();

DR = null;

}

DR = Utils.GetDataRe ader(cnEposSync ,

"Select Top 1 * from ScheduledTasks Where CompletedDate is null and
scheduledfor < getdate() Order By ScheduledFor");

if (DR.Read())

{

// Found Job run tasks

//.....here is where i run the tasks

//run task

DR.Close();

SQL.SqlCommand SQLcmd = new System.Data.Sql Client.SqlComma nd("Update
ScheduledTasks set CompletedDate = getdate() Where Scheduleid = "

+ id,cnEposSync);

// unrem this line to update table

SQLcmd.ExecuteN onQuery();

}

}

catch (Exception ex)

{

Utils.LogEvent( "Error in Timer_Elapsed : " +
ex.Message,Syst em.Diagnostics. EventLogEntryTy pe.Error);

}

finally

{

DR.Close();

DR = null;

}

Timer.Enabled = true;

}
Thanks in advance

--
TimB
Nov 15 '05 #1
3 2169
May be there is a network problem that causes the network to go down and the
service is unable to reconnect to the network when it is back up?

"timb" <ti**@test.co m> wrote in message
news:OD******** ******@TK2MSFTN GP12.phx.gbl...
Hi,
I have created a windows service which is responsible for running
certain tasks when they are scheduled to run. The service monitors a sql
table and runs a task when the task scheduled time is overdue. This service is installed at several sites and on 4 out of 5 sites runs the tasks
correctly on schedule. However on some other sites the task will run one
night but then not run the next night and not subsequent nights. If i stop and start the service on these sites the tasks run immediately. I am also
logging any error messages to the event log and i receive no errors on these sites. The timer event occurs every 10 seconds.

1/Is setting objects to null the correct way to tell the GC that the object is ready for Garbage collection?
2/Any ideas on why the service appears not to be reading the table under
some circumstances.
private static void Timer_Elapsed(o bject sender,
System.Timers.E lapsedEventArgs e)

{

// Poll epossync schedules table for jobs.

Timer.Enabled = false;

SQL.SqlDataRead er DR = null;

try

{

if (DR != null)

{

DR.Close();

DR = null;

}

DR = Utils.GetDataRe ader(cnEposSync ,

"Select Top 1 * from ScheduledTasks Where CompletedDate is null and
scheduledfor < getdate() Order By ScheduledFor");

if (DR.Read())

{

// Found Job run tasks

//.....here is where i run the tasks

//run task

DR.Close();

SQL.SqlCommand SQLcmd = new System.Data.Sql Client.SqlComma nd("Update
ScheduledTasks set CompletedDate = getdate() Where Scheduleid = "

+ id,cnEposSync);

// unrem this line to update table

SQLcmd.ExecuteN onQuery();

}

}

catch (Exception ex)

{

Utils.LogEvent( "Error in Timer_Elapsed : " +
ex.Message,Syst em.Diagnostics. EventLogEntryTy pe.Error);

}

finally

{

DR.Close();

DR = null;

}

Timer.Enabled = true;

}
Thanks in advance

--
TimB

Nov 15 '05 #2
>1/Is setting objects to null the correct way to tell the
GC that the object
is ready for Garbage collection?
Technically you don't need to set objects to null in order
for them to be garbage collected. The garbage collector
builds a dependancy graph of rooted {in use} objects each
time a GC cycle occurs, any unrooted objects will not be
in the graph and thus are subject to collection...
2/Any ideas on why the service appears not to be reading the table undersome circumstances.


Can you enable SQL Server logging on the offending
machine? If so the SQL Server log will tell you date/time
and text of executed queries and you could narrow down the
problem a bit...

How long are the timers running? Days? Weeks? Perhaps you
could try destroying the timer and recreating it more
frequently...

--Richard
Nov 15 '05 #3
Thanks,
however this is unlikely to be the problem as the sql server is
the same server with this application installed.

"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:e3******** ******@TK2MSFTN GP09.phx.gbl...
May be there is a network problem that causes the network to go down and the service is unable to reconnect to the network when it is back up?

"timb" <ti**@test.co m> wrote in message
news:OD******** ******@TK2MSFTN GP12.phx.gbl...
Hi,
I have created a windows service which is responsible for running
certain tasks when they are scheduled to run. The service monitors a sql table and runs a task when the task scheduled time is overdue. This

service
is installed at several sites and on 4 out of 5 sites runs the tasks
correctly on schedule. However on some other sites the task will run one night but then not run the next night and not subsequent nights. If i

stop
and start the service on these sites the tasks run immediately. I am also logging any error messages to the event log and i receive no errors on

these
sites. The timer event occurs every 10 seconds.

1/Is setting objects to null the correct way to tell the GC that the

object
is ready for Garbage collection?
2/Any ideas on why the service appears not to be reading the table under
some circumstances.
private static void Timer_Elapsed(o bject sender,
System.Timers.E lapsedEventArgs e)

{

// Poll epossync schedules table for jobs.

Timer.Enabled = false;

SQL.SqlDataRead er DR = null;

try

{

if (DR != null)

{

DR.Close();

DR = null;

}

DR = Utils.GetDataRe ader(cnEposSync ,

"Select Top 1 * from ScheduledTasks Where CompletedDate is null and
scheduledfor < getdate() Order By ScheduledFor");

if (DR.Read())

{

// Found Job run tasks

//.....here is where i run the tasks

//run task

DR.Close();

SQL.SqlCommand SQLcmd = new System.Data.Sql Client.SqlComma nd("Update
ScheduledTasks set CompletedDate = getdate() Where Scheduleid = "

+ id,cnEposSync);

// unrem this line to update table

SQLcmd.ExecuteN onQuery();

}

}

catch (Exception ex)

{

Utils.LogEvent( "Error in Timer_Elapsed : " +
ex.Message,Syst em.Diagnostics. EventLogEntryTy pe.Error);

}

finally

{

DR.Close();

DR = null;

}

Timer.Enabled = true;

}
Thanks in advance

--
TimB


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6744
by: | last post by:
Hi, I have a Windows Service that uses a referenced dotnet-dll. In my dll I set some public string to a stringvalue that I get from reading a xml-file(my config file). It works fine if I use it in a vb-form. But since Windows Services ? executes? in windows\system32 I can´t locate my xml-config- file. I don´t want to set different "compiling-statements" such as :
3
7830
by: Craig Thompson | last post by:
I've attempted to write a windows service that creates one FileSystemWatcher for each entry in a XML config file. Everything start perfrectly and runs as I expect for about 5 minutes and then after that the FileSystemWatchers seem to stop monitoring... My theory is that for some reason the Garbage Collector is trashing my FileSystemWatchers. Another clue to my situation is that I just took my service and made it into a windows form...
9
7252
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service stopping. Please advise how to stop the service. Thanks, SP
7
3207
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I think the username can be read with user.identity.name.
2
2450
by: Trevor | last post by:
Argh! This problem is driving me nuts! Can you help? In November of 2003, I installed a web service on Windows Server 2003 built in VB.NET for v1.1.4322 of the framework. It contains a timer (System.Timers.Timer) which has an interval of 24 hours. Actually, it reads a time like 2AM out of the config file, and calculates the time between the start of the service to 2AM, and sets the timer. When the timer expires, it re-reads the...
5
4512
by: JM | last post by:
I have created a Windows Service which uses xml file as a data source. The service is running on .NET 2.0 and uses LocalSystem account. It was running fine but now it has started locking the xml file sometimes. When I stop the service it unlocks the file.The service is running all time. And it locks xml file sometimes not always. I would really appreciate if anybody can guide me here. Thanks
6
595
by: Chris Marsh | last post by:
All I have a database table, changes to the data within which I am interested in acting on. The approach that I'm taking is to have the database update a file every time data is updated. This process is outside my domain - I can rely on the file being updated when data changes. Within my domain is the design of a Windows service to perform the operations required when the data changes. I have not produced a Windows service before...
0
2693
by: =?Utf-8?B?U2ltb25EZXY=?= | last post by:
Hi All I would like to install the same Windows Service project on the same server under different names, one for each customer. I have been able to do it but I would like an expert opinion as to whether my solution is robust or whether there is a better way to do it. What I've been trying to do is to create a core project with different extension projects, one for each customer. I wanted to create a different Setup project for each...
0
1598
by: jigsmshah | last post by:
I have a windows service developed in C#.I am reading the connection string from an ini file and also i am reading 3 image file from the bin directory. now the new requirement is that there will be multiple instances of the same windows service running. My concern is that will there be any problem when multiple instances will be reading those above mentioned file.I am not writing to any files in the service. If i try to use lock() when...
0
8472
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.