我在生产中有一个名为 Documents 的文档库。我编写了一个计时器作业,用于根据库中的列发送电子邮件。
在开发环境中一切都很好,但是 prod 中的计时器工作给了我例外。有任何想法吗?
Entering monitored scope (Timer Job Corporate Policies - Reminder Emails)
作业定义 CorporatePolicyReminders.DailySchedule (ID 3586f4d2-1bc1-4770-b5b8-4c2c578ee8d5) 的 Execute 方法抛出异常。更多信息包括在下面。你调用的对象是空的。
异常堆栈跟踪:
在 CorporatePolicyReminders.CorporatePolicyReminders.SendCorporateReminder(SPWeb web)
at CorporatePolicyReminders.DailySchedule.Execute(Guid contentDbId)
at Microsoft.SharePoint.Administration.SPTimerJobInvokeInternal.Invoke(SPJobDefinition jd, Guid targetInstanceId, Boolean isTimerService, Int32& result)
离开监控范围(定时工作公司政策 - 提醒电子邮件)。执行时间=364.288198639771
SendCorporateReminers 方法
public void SendCorporateReminder(SPWeb web)
{
SPList lstComplaint = Helper.GetList(web, "Documents", Helper.ListType.Library);
if (lstComplaint != null)
{
string query = "<Where><Eq><FieldRef Name='DocFormat' /><Value Type='Choice'>Policy</Value></Eq></Where>";
SPListItemCollection colRecords = Helper.ExecuteQueryRecursive(lstComplaint, query, null, 2000);
if (colRecords != null && colRecords.Count > 0)
{
foreach (SPListItem item in colRecords)
{
DateTime Expires = Helper.GetSPFieldDateTimeValue(item, "Expires");
String Title = Helper.GetSPFieldTextValue(item, "Title");
SPFieldUserValueCollection userResp = Helper.GetUsers(item, "Contact");
TimeSpan totaldays = DateTime.Now.Date - Expires.Date;
Int32 days = totaldays.Days;
String emailtemplatekeyA = "AEmail" + days.ToString();
String emailtemplatekeyB = "BEmail" + days.ToString();
String respToEmail = String.Empty;
if (userResp != null && userResp.Count > 0)
{
foreach (SPFieldUserValue user in userResp)
{
if (!string.IsNullOrEmpty(respToEmail))
respToEmail += ",";
respToEmail += user.User.Email;
}
}
HandleEmails handleEmail = new HandleEmails();
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.EmailRecipient, PlaceHolder.USERRESP.ToString(), respToEmail);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.TITLE.ToString(), Title);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.EXPDT.ToString(), Expires.ToShortDateString());
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.ID.ToString(), item.ID.ToString());
handleEmail.SendMail(web, emailtemplatekeyA);
handleEmail = new HandleEmails();
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.EmailRecipient, PlaceHolder.USERRESP.ToString(), respToEmail);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.TITLE.ToString(), Title);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.EXPDT.ToString(), Expires.ToShortDateString());
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.ID.ToString(), item.ID.ToString());
handleEmail.SendMail(web, emailtemplatekeyB);
}
}
}
}`