[英]SQL Server 2005 Asnyc stored procedure
I am currently having problems calling a stored procedure async from within a insert-update-trigger. 我目前在从insert-update-trigger内部调用存储过程异步时遇到问题。 For this I m using the service broker. 为此,我正在使用服务代理。
--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]);
Within the trigger: 在触发器内:
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');
Within the stored procedure: 在存储过程中:
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
This setup doesn't seem to work. 此设置似乎无效。 The trigger does not throw any errors so I assume the message is queued. 触发器不会引发任何错误,因此我假设消息已排队。 But the receive within the stored doesn't seem to work. 但是存储中的接收似乎不起作用。 None of my statements are being executed. 我的语句均未执行。
sys.transmission_queue
. 检查消息是否未保留在sys.transmission_queue
。 Transmission_status column should explain why the message isn't delivered. Transmission_status列应说明为什么未传递邮件。 SELECT ... FROM [TheQueue]
. 检查消息是否在队列中: SELECT ... FROM [TheQueue]
。 If the message is there and the procedure didn't activate check the queue's is_receive_enabled status in sys.service_queues . 如果消息是存在的,程序没有激活检查队列的状态is_receive_enabled sys.service_queues 。 If the queue is disabled, you probably rolled back 5 receives in a row during testing and triggered the poison message mechanism . 如果禁用了队列,则可能在测试期间连续回滚5个接收并触发了有毒消息机制 。 Ok, thanks for your answers, I fixed it. 好的,谢谢您的回答,我已将其修复。
The problem was that the service broker was disabled.. 问题是服务代理已禁用。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.