1

我刚刚继承了一个使用服务代理的 SQL Server 2005 数据库(这是一个更大的项目/解决方案的一部分)。关于解决方案的一切工作正常。我正在尝试了解服务代理 SQL,我看到了这个语句。

BEGIN DIALOG CONVERSATION @h
FROM SERVICE foo_Init
TO SERVICE 'foo_Target'
ON CONTRACT fooContract

为什么 foo_Init 不在单引号中?我希望它会像“foo_Target”一样。

4

2 回答 2

2

From Books On Line

BEGIN DIALOG [ CONVERSATION ] @dialog_handle
   FROM SERVICE initiator_service_name
   TO SERVICE 'target_service_name'
       [ , { 'service_broker_guid' | 'CURRENT DATABASE' } ] 
   [ ON CONTRACT contract_name ]
   [ WITH
   [  { RELATED_CONVERSATION = related_conversation_handle 
      | RELATED_CONVERSATION_GROUP = related_conversation_group_id } ] 
   [ [ , ] LIFETIME = dialog_lifetime ] 
   [ [ , ] ENCRYPTION = { ON | OFF }  ] ]
[ ; ]

FROM SERVICE initiator_service_name Specifies the service that initiates the dialog. The name specified must be the name of a service in the current database. The queue specified for the initiator service receives messages returned by the target service and messages created by Service Broker for this conversation.

TO SERVICE 'target_service_name' Specifies the target service with which to initiate the dialog. The target_service_name is of type nvarchar(256). Service Broker uses a byte-by-byte comparison to match the target_service_name string. In other words, the comparison is case-sensitive and does not take into account the current collation.

于 2010-02-17T22:00:57.967 回答
2

FROM SERVICE 必须是当前数据库中的服务,即您可以立即使用的服务。因此,您需要通过它的系统名来引用它。另一方面,服务只是“外面的东西”。在执行 BEGIN DIALOG 语句时,它甚至可能不存在。当需要发送消息时,Service Broker 路由会发挥作用,并告诉 Service Broker “外面的东西”实际位于何处以及如何到达它。因此,仅当目标服务位于同一数据库中时,通过 sysname 引用目标服务(就像使用启动器服务一样)才有意义,但情况可能并非总是如此。

于 2010-02-18T16:18:40.380 回答