473,385 Members | 1,927 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,385 software developers and data experts.

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(object sender,
System.Timers.ElapsedEventArgs e)

{

// Poll epossync schedules table for jobs.

Timer.Enabled = false;

SQL.SqlDataReader DR = null;

try

{

if (DR != null)

{

DR.Close();

DR = null;

}

DR = Utils.GetDataReader(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.SqlClient.SqlCommand("Update
ScheduledTasks set CompletedDate = getdate() Where Scheduleid = "

+ id,cnEposSync);

// unrem this line to update table

SQLcmd.ExecuteNonQuery();

}

}

catch (Exception ex)

{

Utils.LogEvent("Error in Timer_Elapsed : " +
ex.Message,System.Diagnostics.EventLogEntryType.Er ror);

}

finally

{

DR.Close();

DR = null;

}

Timer.Enabled = true;

}
Thanks in advance

--
TimB
Nov 15 '05 #1
3 2156
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.com> wrote in message
news:OD**************@TK2MSFTNGP12.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(object sender,
System.Timers.ElapsedEventArgs e)

{

// Poll epossync schedules table for jobs.

Timer.Enabled = false;

SQL.SqlDataReader DR = null;

try

{

if (DR != null)

{

DR.Close();

DR = null;

}

DR = Utils.GetDataReader(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.SqlClient.SqlCommand("Update
ScheduledTasks set CompletedDate = getdate() Where Scheduleid = "

+ id,cnEposSync);

// unrem this line to update table

SQLcmd.ExecuteNonQuery();

}

}

catch (Exception ex)

{

Utils.LogEvent("Error in Timer_Elapsed : " +
ex.Message,System.Diagnostics.EventLogEntryType.Er ror);

}

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.com> wrote in message
news:e3**************@TK2MSFTNGP09.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.com> wrote in message
news:OD**************@TK2MSFTNGP12.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(object sender,
System.Timers.ElapsedEventArgs e)

{

// Poll epossync schedules table for jobs.

Timer.Enabled = false;

SQL.SqlDataReader DR = null;

try

{

if (DR != null)

{

DR.Close();

DR = null;

}

DR = Utils.GetDataReader(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.SqlClient.SqlCommand("Update
ScheduledTasks set CompletedDate = getdate() Where Scheduleid = "

+ id,cnEposSync);

// unrem this line to update table

SQLcmd.ExecuteNonQuery();

}

}

catch (Exception ex)

{

Utils.LogEvent("Error in Timer_Elapsed : " +
ex.Message,System.Diagnostics.EventLogEntryType.Er ror);

}

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
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...
3
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...
9
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...
7
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...
2
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...
5
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...
6
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...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...

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.