我想最简单的方法是通过在SQL Server代理中创建一个新作业来每天调用您的存储过程,而不是尝试在编写的应用程序中实现这一目标。
有关创建SQL作业的更多信息,请参见以下链接。
编辑- 对不起 ,我真的不应该在做其他工作时也回答此类帖子。我完全想念您要发送电子邮件的事实,让您想到要在屏幕上报告过期记录。咄。
要在每天的特定时间发送过期的电子邮件,我想Windows服务当然可以完成这项工作,但似乎有点过头了,您需要完全控制正在运行的服务器。
您可以设置一个计划任务来每天调用sendOverdueMail.aspx网页来完成这项工作?
显然也有SQL Server代理的电子邮件选项,尽管我不确定您对将产生的电子邮件格式有多少控制权。
最后,本教程通过挂钩ASP.net服务器上的缓存过期事件,逐步创建预定的任务类型效果,然后允许您调用电子邮件代码。
private const string DummyCacheItemKey = "GagaGuguGigi";protected void Application_Start(Object sender, EventArgs e){ RegisterCacheEntry();}private bool RegisterCacheEntry(){ if( null != HttpContext.Current.Cache[ DummyCacheItemKey ] ) return false; HttpContext.Current.Cache.Add( DummyCacheItemKey, "Test", null, DateTime.MaxValue, TimeSpan.FromMinutes(1), CacheItemPriority.Normal, new CacheItemRemovedCallback( CacheItemRemovedCallback ) ); return true;}public void CacheItemRemovedCallback( string key, object value, CacheItemRemovedReason reason){ Debug.WriteLine("Cache item callback: " + DateTime.Now.ToString() ); // send reminder emails here DoWork();}


