你能/应该使用SQL Server服务代理与.NET应用程序? [英] Can you/should you use SQL Server Service Broker with .NET applications?

查看:119
本文介绍了你能/应该使用SQL Server服务代理与.NET应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在需要触发的应用code数据库的许多操作。目前我使用的数据库查询,但我听到的SQL Server服务中介可以给我MSMQ一样的功能。

  1. 我可以倾听来自不同的机器?
  2. 在运行的.NET应用程序的SQL Server Service Broker的队列
  3. 如果是这样,我该怎么办呢?
  4. 如果没有,你有什么建议?
解决方案

要回答你的问题:

  

我可以听的SQL Server服务   从.NET应用程序代理队列   在不同的机器上运行?

是的。

  

如果是这样,我该怎么办呢?

     

如果没有,你有什么建议?

您可以考虑使用的SqlDependency 。它使用服务代理在幕后,但没有明确。

您可以注册一个 SELECT 查询或存储过程的的SqlDependency 对象。如果另一个命令改变从查询返回的数据,那么事件将触发。你可以注册一个事件处理程序,并运行任何code你想在那个时候。或者,你可以使用的SqlCacheDependency ,这只是从缓存中删除关联对象时,事件触发。

您也可以使用服务代理直接。然而,在这种情况下,你将需要发送和接收自己的消息,与MSMQ。

在负载平衡的环境中,的SqlDependency 是良好的,其中code需要每个Web服务器上运行的情况下(如清空缓存)。 Service Broker消息是更好地为code比应该只运行一次 - 如发送电子邮件

在情况下,它可以帮助,我将介绍这两个系统在细节,在我的书的例子(超快速ASP.NET )。

I have many operations in the database that need to trigger application code. Currently I am using database polling, but I hear that SQL Server Service Broker can give me MSMQ-like functionality.

  1. Can I listen to SQL Server Service Broker queues from .NET applications running on a different machine?
  2. If so, should I do it?
  3. If not, what would you recommend?

To answer your questions:

Can I listen to SQL Server Service Broker queues from .NET applications running on a different machine?

Yes.

If so, should I do it?

If not, what would you recommend?

You might consider using SqlDependency. It uses Service Broker behind the scenes, but not explicitly.

You can register a SqlDependency object with a SELECT query or a stored procedure. If another command changes the data that was returned from the query, then an event will fire. You can register an event handler, and run whatever code you like at that time. Or, you can use SqlCacheDependency, which will just remove the associated object from the Cache when the event fires.

You can also use Service Broker directly. However, in that case you will need to send and receive your own messages, as with MSMQ.

In load-balanced environments, SqlDependency is good for cases where code needs to run on every web server (such as flushing the cache). Service Broker messages are better for code than should only run once -- such as sending an email.

In case it helps, I cover both systems in detail with examples in my book (Ultra-Fast ASP.NET).

这篇关于你能/应该使用SQL Server服务代理与.NET应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆