★★★★★实时查询数据库某个字段的值,然后根据值给用户发邮件★★★★★ ---------在线急等! ★★★★★实时监控数据库某个字段的值,然后根据值给用户发邮件★★★★★ 比如A表的stateID字段,(int型,默认是0) 如果突然变为1了.我就要马上给用户发邮件.邮件我知道发,问题是怎么样实时监控这个字段是否改变.最好是有具体的代码.谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 触发器可以判断stateID字段的更新过程,但是不能回发控制程序代码。 做一个timer吧,过一段时间检测一下数据,发现不同就执行法邮件的操作 每分鐘執行一次的主控台程式:private void InitializeComponent() { this.TestPrg = new System.Diagnostics.EventLog(); this.timer1 = new System.Timers.Timer(); this.ConfigWatcher = new System.IO.FileSystemWatcher(); ((System.ComponentModel.ISupportInitialize)(this.TestPrg)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ConfigWatcher)).BeginInit(); // // TestPrg // this.TestPrg .Log = "TestPrg "; this.TestPrg .Source = "Test"; // // timer1 // this.timer1.Enabled = true; this.timer1.Interval = 60000; this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed); // // ConfigWatcher // this.ConfigWatcher.EnableRaisingEvents = true; this.ConfigWatcher.Filter = "test.xml"; this.ConfigWatcher.Changed += new System.IO.FileSystemEventHandler(this.ConfigWatcher_Changed); // // TestPrg // this.ServiceName = "TestService"; ((System.ComponentModel.ISupportInitialize)(this.TestPrg)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.ConfigWatcher)).EndInit(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } /// <summary> /// 設定使服務能開始執行的事務。 /// </summary> protected override void OnStart(string[] args) { // TODO: 在此加入啟動服務的程式碼。 this.timer1.Enabled = true; this.WriteLog ("OnStart",false); } /// <summary> /// 停止這項服務。 /// </summary> protected override void OnStop() { // TODO: 在此加入停止服務所需執行的終止程式碼。 this.timer1.Enabled = false; this.WriteLog ("OnStop",false); } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //發Email通知 try { SendMail(); } catch { this.WriteLog ("Error!",true); } } 大家觉得这样好不,我在插入A表的时候做个触发器把那个字段的值关联到令一个表,然后用timer 检测那个表.因为那个表的数据流比A表的要小,所以效率要高?这可以吗? 问题不出现在实时查询值的问题上。这个1是怎么来的,楼主要说清楚。如果说1是从一个端口监听而来,那么好,这个问题和web就一点关系也没有。只要监听到指定端口来的数据是1,就发一封邮件。如果说1是用户填入的,那么直接在填写1的时候发一封邮件就完事了。所以,楼主一定要交待1从何而来?? exec msdb..sp_send_dbmail @profile_name = '报表通知邮件配置' -- profile 名称,@recipients = '[email protected]' -- 收件人邮箱,@subject = 'SQL Server 2005 Mail Test' -- 邮件标题,@body = 'Hello Mail!' -- 邮件内容,@body_format = 'TEXT' -- 邮件格式测试环境: 1 Windows 2000 Server 2 SQL Server 2000+SP3 3 Microsoft Outlook (Office 2000) 准备一个Internet邮件帐户: 测试电子邮件帐户:[email protected] Smtp服务器 smtp.163.com pop3服务器 pop.163.com 步骤一: 更改电子邮件配置 1 打开Microsoft Outlook 单击“工具”菜单中的“选项”,然后单击“邮件服务”选项卡。 2 单击“重新配置邮件支持”。 3 选择“用于企业或工作组”选项 4 重新启动Microsoft Outlook 步骤二: 添加配置文件 1 单击“工具”菜单中的“服务”,然后单击“添加”按钮。 2 选择"Internet 电子邮件",单击“确定”。 3 下面的步骤是设置电子邮件帐号,请参考Microsoft Outlook帮助文件,这里不再赘述。 4 利用配置好的电子邮件帐号收发邮件,确认配置成功。 步骤三: 配置MSSQLSERVER服务采用邮件配置文件 1 重新启动MSSQLSERVER服务(必须的,否则MSSQLSERVER服务检测不到上一步骤添加的配置文件) 2 打开企业管理器->展开服务器->支持服务->右击"邮件"->点击下拉框,你会发现 "Microsoft Outlook Internet Settings"选项,点击"测试"。如果弹出表示成功的对话框,那恭喜你,已经 大功告成了。 步骤四:享受你的劳动成果 1 打开SQL Server的查询分析器 2 输入下列SQL语句,执行 exec master..xp_sendmail '[email protected]','Hello,World!' 3 好了,去你的邮箱收邮件去吧! 注意事项:以上的配置过程要求以MSSQLSERVER服务采用的Windows帐号登录Windows 2000 Server,即你登录计算机所采用的帐号要和MSSQLSERVER服务采用的Windows帐号相同。 写一个触发器create trigger a on table1for insertasexec msdb..sp_send_dbmail @profile_name = '报表通知邮件配置' -- profile 名称,@recipients = '[email protected]' -- 收件人邮箱,@subject = 'SQL Server 2005 Mail Test' -- 邮件标题,@body = 'Hello Mail!' -- 邮件内容,@body_format = 'TEXT' -- 邮件格式...http://www.cnblogs.com/Magicsky/archive/2009/02/25/1398205.html 通过触发器记录操作日志,再根据TIMER实现定时修改活泼又任务实现修改 一般的做法是在你程序中修改数据库中对象的某个你设定的某个值的时候判断,是否符合你的发邮件条件,如果符合,然后同时再建一个发邮件的表,插入要发的邮件相关内容。然后创建一个windows服务,每隔几分种运行一次,把邮件表中的邮件发出去。 求达人将VB代码转为C#代码! 关于event.keyCode允许小写字母的问题 aspnetpager+存储过程分页问题 网页用户自定义编辑图片? 怎么从MSSQL2000的LOG中恢复数据呀!很急! 在窗体前弹出有选择对话框 求教,asp.net从客户端读取的数据是乱码 用javascript写的二级连动 显示数据用的是listbox 我在asp.net里面最listbox的值取不出来,求救 !! 谁能给我一个提示(菜鸟问题),请大家不要笑哟 Substring()的问题。 在字符串中怎么查找某个字符 AJAXPRO 好像不能用,急啊
{
this.TestPrg = new System.Diagnostics.EventLog();
this.timer1 = new System.Timers.Timer();
this.ConfigWatcher = new System.IO.FileSystemWatcher();
((System.ComponentModel.ISupportInitialize)(this.TestPrg)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ConfigWatcher)).BeginInit();
//
// TestPrg
//
this.TestPrg .Log = "TestPrg ";
this.TestPrg .Source = "Test";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 60000;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
//
// ConfigWatcher
//
this.ConfigWatcher.EnableRaisingEvents = true;
this.ConfigWatcher.Filter = "test.xml";
this.ConfigWatcher.Changed += new System.IO.FileSystemEventHandler(this.ConfigWatcher_Changed);
//
// TestPrg
//
this.ServiceName = "TestService";
((System.ComponentModel.ISupportInitialize)(this.TestPrg)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ConfigWatcher)).EndInit(); } protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} /// <summary>
/// 設定使服務能開始執行的事務。
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: 在此加入啟動服務的程式碼。
this.timer1.Enabled = true;
this.WriteLog ("OnStart",false);
}
/// <summary>
/// 停止這項服務。
/// </summary>
protected override void OnStop()
{
// TODO: 在此加入停止服務所需執行的終止程式碼。
this.timer1.Enabled = false;
this.WriteLog ("OnStop",false);
} private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//發Email通知
try
{
SendMail();
}
catch
{
this.WriteLog ("Error!",true);
}
}
然后用timer 检测那个表.因为那个表的数据流比A表的要小,所以效率要高?
这可以吗?
只要监听到指定端口来的数据是1,就发一封邮件。如果说1是用户填入的,那么直接在填写1的时候发一封邮件就完事了。所以,楼主一定要交待1从何而来??
@profile_name = '报表通知邮件配置' -- profile 名称
,@recipients = '[email protected]' -- 收件人邮箱
,@subject = 'SQL Server 2005 Mail Test' -- 邮件标题
,@body = 'Hello Mail!' -- 邮件内容
,@body_format = 'TEXT' -- 邮件格式测试环境:
1 Windows 2000 Server
2 SQL Server 2000+SP3
3 Microsoft Outlook (Office 2000)
准备一个Internet邮件帐户:
测试电子邮件帐户:[email protected]
Smtp服务器 smtp.163.com
pop3服务器 pop.163.com
步骤一: 更改电子邮件配置
1 打开Microsoft Outlook 单击“工具”菜单中的“选项”,然后单击“邮件服务”选项卡。
2 单击“重新配置邮件支持”。
3 选择“用于企业或工作组”选项
4 重新启动Microsoft Outlook
步骤二: 添加配置文件
1 单击“工具”菜单中的“服务”,然后单击“添加”按钮。
2 选择"Internet 电子邮件",单击“确定”。
3 下面的步骤是设置电子邮件帐号,请参考Microsoft Outlook帮助文件,这里不再赘述。
4 利用配置好的电子邮件帐号收发邮件,确认配置成功。
步骤三: 配置MSSQLSERVER服务采用邮件配置文件 1 重新启动MSSQLSERVER服务(必须的,否则MSSQLSERVER服务检测不到上一步骤添加的配置文件)
2 打开企业管理器->展开服务器->支持服务->右击"邮件"->点击下拉框,你会发现
"Microsoft Outlook Internet Settings"选项,点击"测试"。如果弹出表示成功的对话框,那恭喜你,已经 大功告成了。
步骤四:享受你的劳动成果
1 打开SQL Server的查询分析器
2 输入下列SQL语句,执行
exec master..xp_sendmail '[email protected]','Hello,World!'
3 好了,去你的邮箱收邮件去吧!
注意事项:以上的配置过程要求以MSSQLSERVER服务采用的Windows帐号登录Windows 2000 Server,即你登录计算机所采用的帐号要和MSSQLSERVER服务采用的Windows帐号相同。
create trigger a on table1
for insert
asexec msdb..sp_send_dbmail
@profile_name = '报表通知邮件配置' -- profile 名称
,@recipients = '[email protected]' -- 收件人邮箱
,@subject = 'SQL Server 2005 Mail Test' -- 邮件标题
,@body = 'Hello Mail!' -- 邮件内容
,@body_format = 'TEXT' -- 邮件格式
...http://www.cnblogs.com/Magicsky/archive/2009/02/25/1398205.html
是否符合你的发邮件条件,如果符合,然后同时再建一个发邮件的表,插入要发的邮件相关内容。然后创建一个windows服务,每隔几分种运行一次,把邮件表中的邮件发出去。