2010-01-17 323 views
0

我目前在插入更新觸發器中調用存儲過程異步時出現問題。爲此我使用服務代理。SQL Server 2005 Asnyc存儲過程

--message type 
CREATE MESSAGE TYPE [TheMessage] VALIDATION = NONE 

--contract 
CREATE CONTRACT [TheContract] ([TheMessage] SENT BY ANY); 

--queue 
CREATE QUEUE [TheQueue] WITH ACTIVATION 
(STATUS = ON, MAX_QUEUE_READERS = 1, 
PROCEDURE_NAME = TheStoreProcedure, 
EXECUTE AS OWNER); 

--service 
CREATE SERVICE [TheService] ON QUEUE [TheQueue] ([TheContract]); 

在觸發器:

DECLARE @Handle UNIQUEIDENTIFIER; 

BEGIN DIALOG CONVERSATION @Handle 
FROM SERVICE [TheService] 
TO SERVICE 'TheService' 
ON CONTRACT [TheContract] 
WITH ENCRYPTION = OFF; 

SEND ON CONVERSATION @Handle 
MESSAGE TYPE [TheMessage](N'some data'); 

在存儲過程:

DECLARE @Handle UNIQUEIDENTIFIER; 
DECLARE @MessageType SYSNAME; 

RECEIVE TOP (1) 
@Handle = conversation_handle, 
@MessageType = message_type_name 
FROM [TheQueue]; 

IF(@Handle IS NOT NULL) 

BEGIN 

-- some statements 

END 

此設置似乎並沒有工作。觸發器不會拋出任何錯誤,所以我假設消息已排隊。但存儲內的接收似乎不起作用。我的任何陳述都沒有被執行。

回答

0

好的,感謝您的回答,我解決了它。

的問題是業務代理被禁用..

USE AdventureWorks 
GO 

ALTER DATABASE AdventureWorks SET SINGLE_USER WITH ROLLBACK IMMEDIATE 
ALTER DATABASE AdventureWorks SET ENABLE_BROKER 
ALTER DATABASE AdventureWorks SET MULTI_USER 
GO 
2