本文介绍了从的SqlDependency获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,并正在等待新的插入一个的SqlDependency。
的OnChange火灾,因为我需要,但我不是否有可能得到这导致DATABSE变化的行了解。
的SqlDependency SQL命令:
CMD的SqlCommand =新的SqlCommand(SELECT ID FROM dbo.DataRequests,m_sqlConn) ;
的OnChange代码:
私人无效的OnChange(对象发件人,SqlNotificationEventArgs E)
{
的SqlDependency依赖=发件人为的SqlDependency;
dependency.OnChange - =的OnChange;
Console.WriteLine(信息:+ e.Info.ToString());
Console.WriteLine(稿件来源:+ e.Source.ToString());
Console.WriteLine(类型:+ e.Type.ToString());
Console.WriteLine(DateTime.Now);
的getMessages();
}
解决方案
没有信息提供有关导致依赖被解雇的行。
我想作为一个解决办法,你总是可以把一个时间戳在您的记录和跟踪事件时,最后发射
I've got a table and a SqlDependency that is waiting for new inserts.
OnChange fires as I need, but I don't understand if it's possible to get the row which cause the databse change.
SqlDependency sql command:
SqlCommand cmd = new SqlCommand("SELECT id FROM dbo.DataRequests", m_sqlConn);
OnChange code:
private void OnChange(object sender, SqlNotificationEventArgs e)
{
SqlDependency dependency = sender as SqlDependency;
dependency.OnChange -= OnChange;
Console.WriteLine("Info: " + e.Info.ToString());
Console.WriteLine("Source: " + e.Source.ToString());
Console.WriteLine("Type: " + e.Type.ToString());
Console.WriteLine(DateTime.Now);
GetMessages();
}
解决方案
No information is available about the rows that caused the dependency to be fired.
I guess as a workaround you could always put a timestamp on your records and track when the event was last fired.
这篇关于从的SqlDependency获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!