Windows service not reading sql table

  • Thread starter Thread starter timb
  • Start date Start date
T

timb

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.Error);

}

finally

{

DR.Close();

DR = null;

}

Timer.Enabled = true;

}


Thanks in advance
 
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?
 
Thanks,
however this is unlikely to be the problem as the sql server is
the same server with this application installed.

Eliyahu Goldin said:
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?
 
Back
Top