I have created a scheduler that runs every 10 minutes to check a table and if any data exists in that table then it sends emails to those persons accordingly. I am using Visual Studio 2010. I installed Quartz and added it in my bin and references also. It is working perfectly in my local and in my testing environment also. I added some logs just to make sure the scheduler is triggering and it inserts data into my table after every 10 minutes.
Now I deployed it on the client environment.
I have this function in my global.asax.cs file
JobScheduler.Start();
Which is getting triggered fine. I also added some logs in my JobSchdeuler.cs file and the code is perfectly running till the last line then it should hit the emailtrigger.cs file and execute whatever code is written but this file is not getting triggered. Just to let you know EmailTriggerOnApproval is returning Y. After that I have added a log just to make sure my code is working. and there seems to be no entry in table after ''Start Hit 6''
here is my code
JobScehduler.cs
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<EmailTrigger>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInMinutes(10)
.OnEveryDay()
.InTimeZone(TimeZoneInfo.Local) //added later
)
.Build();
scheduler.ScheduleJob(job, trigger);
obj.execute("insert into EmailSendLogs(Message,Date) values('Start Hit 6',getdate())");
}
And EmailTrigger.cs
public void Execute(IJobExecutionContext context)
{
try
{
clsEmail objEmail = new clsEmail();
if (dtLayer.getValueFromStaticConfiguration("EmailTriggerOnApproval", "N") == "Y")
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values ('Trigger started 1','Trigger started 1' , GetDate())");
DataTable dtData = dtLayer.getDataTableFromQuery("select * from EmailSendData where IsSend is null");
if (dtData.Rows.Count > 0)
{
for (int i = 0; i < dtData.Rows.Count; i++)
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values ('Trigger started 2','Trigger started 2' , GetDate())");
string NomineeList = dtData.Rows[i]["NomineeUser"].ToString();
string FromEmpid = dtData.Rows[i]["FromEmpID"].ToString();
string EmailID = dtData.Rows[i]["EmailID"].ToString();
string url = dtData.Rows[i]["URL"].ToString();
string Type = dtData.Rows[i]["Type"].ToString();
string query = dtData.Rows[i]["EmailDetails"].ToString();
string UserID = dtData.Rows[i]["UserID"].ToString();
string NotificationID = dtData.Rows[i]["NotificationID"].ToString();
string CCMail = dtData.Rows[i]["CCMail"].ToString();
string ApprovalCode = dtData.Rows[i]["ApprovalCode"].ToString();
string Id = dtData.Rows[i]["ID"].ToString();
DataTable dtEmailDetails = dtLayer.getDataTableFromQuery(query);
ArrayList emailDetails = dtLayer.datatableTOarraylist(dtEmailDetails);
emailDetails.Add(ApprovalCode);
if (dtLayer.getValueFromStaticConfiguration("SendEmail", "N") == "Y")
objEmail.sendMailNewFunction(NomineeList, FromEmpid, EmailID, url, Type, "", emailDetails, UserID, false, null, NotificationID, CCMail);
dtLayer.execute("update EmailSendData set isSend='Y' where ID= " + Id + " ");
}
}
else
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values ('Job ran successfully','No approved cases pending' , GetDate())");
}
}
}
catch (Exception e)
{
dtLayer.execute(@"Insert into EmailSendLogs(Message,Description,Date)
values (" + dtLayer.checkNull(e.ToString()) + ",'Exception Catch',GetDate())");
throw e;
}
}
Why is it that JobSceduler.cs is working perfectly fine but my EmailTrigger.cs class is not getting triggered. Can anybody tell me what am I doing wrong?