SQL Server - Ole自动化程序内部队列激活过程

时间:2017-09-02 15:16:03

标签: sql-server stored-procedures service-broker ole-automation

我想在插入表中的行时调用Webservice。 所以我启用Ole Automation Procedures,像下面一样调用Webservice,一切都很顺利。

--enabling 'Ole Automation Procedures'
sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE;  
GO  
sp_configure 'Ole Automation Procedures', 1;
GO  
RECONFIGURE;  
GO  

--calling Webservice
create PROCEDURE callwebservice
@url varchar(128)=null  
AS
    Declare @Object as Int;
    Declare @ResponseText as varchar(8000);
    Exec sp_OACreate 'MSXML2.ServerXMLHttp.3.0', @Object OUT;
    Exec sp_OAMethod @Object, 'open', NULL, 'get', @url ,'false'

    Exec sp_OAMethod @Object, 'send'
    Exec sp_OAGetProperty @Object, 'ResponseText', @ResponseText OUTPUT
    Exec sp_OADestroy @Object
return

但是,由于Webservice调用非常冗长,我需要使用Service Broker来完成。所以我创建了一个新的存储过程并将其作为Queue的激活参数传递给我:

--declare procedure
create procedure handleNewMessageInQueue
as
begin
DECLARE @TargetDlgHandle UNIQUEIDENTIFIER
DECLARE @ReplyMessage xml
DECLARE @ReplyMessageName 
BEGIN TRAN;
receive top(1) 
@TargetDlgHandle =Conversation_handle
,@ReplyMessage = Message_Body
,@ReplyMessageName = Message_Type_Name
from newUserQueue;
if @ReplyMessageName = '//goodType'
begin
    exec callwebservice 'http://path/to/my/webservice'
end
commit tran;
end

--declare queue
create queue myQueue
    with ACTIVATION (
    PROCEDURE_NAME = handleNewMessageInQueue,
    MAX_QUEUE_READERS =100,
    EXECUTE AS owner
);

但这次没有发送请求。我检查了一下,我发现sp_OACreate方法没有创建Object,因为@Object的值在执行后是null。此外,当我致电sp_OAGetErrorInfo以获取错误信息时,所有内容均为null

我正在使用SQL Server 2016

如果你能在这里找到问题我很感激。

修改

我发现如果我在该数据库上启用TRUSTWORTHY,一切都会好起来的。但启用它can open security hole

还有更好的方法吗?

0 个答案:

没有答案