我无法使用Windows服务更新数据库,我有下一个代码:
1)启动服务,然后创建一个计时器,并将其设置为3分钟以启动Method ConsultarGroupales。
protected override void OnStart(string[] args)
{
timer = new Timer(porTresMinutos);
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Enabled = true;
timer.Start();
}
public void timer_Elapsed(object sender, ElapsedEventArgs e)
{
ConsultaGrupales();
}
2)ConsultarGrupales使用此方法执行存储过程,然后将项目循环发送到方法EnviarGroupals
public void ConsultaGrupales()
{
Stopwatch tiempo = Stopwatch.StartNew();
List <GroupReservationNotif> data = null;
using (OperaEntities db= new OperaEntities())
{
data = (from gr in MytableInformation gr).ToList();
}
foreach (var item in data)
{
EnviarGroupals(item);
}
}
3)EnviarGroupals此方法在DB上接收对象并更新表
public void EnviarGroupals(GroupReservationNotif groupals)
{
using(OperaEntities db=new OperaEntities())
{
db.UpdateStatusGroupReservations(IsCanceled, Id, IsCompleted, IsFaulted, Status, groupals.Resv_Name_ID, IdEstado);
}
}
4)问题是服务每3分钟正确执行一次,但是在内核更新UpdateStatusGroupReservations时出现错误。