简体   繁体   English

从Service Broker调用时,存储过程失败,但从SSMS运行

[英]Stored procedure fails when called from Service Broker but runs from SSMS

We are using Service Broker in SQL Server 2008R2 as a simple job scheduler. 我们将SQL Server 2008R2中的Service Broker用作简单的作业计划程序。 We send a message to the broker and it sets it to process on the requested date/time. 我们向代理发送一条消息,并将其设置为在请求的日期/时间进行处理。

We have a job (stored procedure) that gets automatically scheduled by user actions in a Sharepoint site, and it's been running just fine for about a year. 我们有一个作业(存储过程),该作业由Sharepoint站点中的用户操作自动安排,并且已经运行了大约一年。 This stored procedure creates 2 tables if they don't exist, truncates them if they do exist, then calls 2 other stored procedures (in series) to populate each of the tables. 该存储过程将创建2个表(如果不存在),将它们截断(如果存在),然后调用2个其他存储过程(依次)以填充每个表。

A few weeks ago, the 2nd of the two stored procedures started failing when the main proc "job" was initiated by the SB. 几周前,当主proc“作业”由SB启动时,两个存储过程中的第二个开始出现故障。 If I go into SSMS, I can execute the "job" stored procedure and it runs to completion without issue (ie both called stored procedures execute without issue, and both tables are populated). 如果我进入SSMS,我可以执行“作业”存储过程,并且可以毫无问题地运行到完成(即,两个被调用的存储过程都可以无问题地执行,并且两个表都已填充)。

Our company, in its infinite wisdom, decided to terminate the guy who set up the Service Broker and wrote these stored procedures. 我们公司以无限的智慧决定终止建立Service Broker并编写这些存储过程的人。 I understand the stored procedures, and am beginning to get a bit of a handle on SB, but I'm at a loss as to why the 2nd stored procedure will execute from SSMS, but fails when called from the Service Broker. 我了解存储过程,并且开始对SB有所了解,但是我不知道为什么第二个存储过程将从SSMS执行,但是从Service Broker调用时失败。

The only thing I can think of is that the Service was created with this command: 我唯一能想到的就是该服务是通过以下命令创建的:

CREATE SERVICE [//ScheduledJobService]
AUTHORIZATION [user ID]
ON QUEUE [dbo].[ScheduledJobQueue] ([//ScheduledJobContract])

and that something happened with his ID on the date that it stopped working. 在停止工作之日,他的ID发生了问题。 However, that doesn't account for why part of the code will execute, and how other tasks in the Service Broker are continuing to execute. 但是,这并不说明为什么要执行部分代码,以及Service Broker中的其他任务如何继续执行。

I'm at a loss for where to look and how to track this down, so any trouble shooting tips would be greatly appreciated. 我不知道在哪里查找以及如何进行跟踪,因此,解决任何麻烦的技巧将不胜感激。

Service broker, as a background process, needs to run things as certain users. 服务代理作为后台进程,需要以某些用户身份运行。 In my broker installations I have normally created a special user for this (ie Broker_User ) with rights to whatever it needs to execute and nothing else. 通常,在我的代理安装中,我为此创建了一个特殊用户(即Broker_User ),该用户具有执行所需权限的权限,而没有其他权限。

If the authorizing account for that service or for the broker queue activation procedure is revoked, things will fail. 如果该服务或代理队列激活过程的授权帐户被吊销,则一切都会失败。

To really trace this we need to know: 要真正追踪这一点,我们需要知道:

  • The details of the queue (create statement etc) 队列的详细信息(create语句等)
  • The details of the activation procedure referenced above 上面提到的激活程序的细节
  • Information about the accounts involved 有关所涉及帐户的信息

It's also possible there's code inside one of the SPs that uses EXECUTE AS which would cause an issue if the account is removed or revoked. 在其中一个使用EXECUTE AS的SP中也可能存在代码,如果删除或撤消帐户,则会导致问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 存储过程成功运行,但从作业中调用时失败 - Stored procedure runs successfully but fails when called from a job 从Service Broker激活时存储过程缓慢 - Slow stored procedure when activated from Service Broker 存储过程不是从Web服务执行的,而是在SSMS中执行的 - Stored procedure doesn't execute from a web service, but does in SSMS 从Web服务调用存储过程失败 - Call to stored procedure fails from Web Service SQL Server 2008-使用SqlDataAdapter从WPF服务调用时,存储过程被卡住 - SQL Server 2008 - Stored Procedure Gets Stuck When Called From WPF Service Using a SqlDataAdapter 存储过程失败,但在手动运行时可正常工作 - Stored procedure fails, but works correctly when it runs manually 从VBA调用时,存储过程中的删除会以静默方式失败 - Deletes in a stored procedure fail silently when called from VBA DTEXEC执行时超时-但仅在从存储过程中调用时 - Timeout on DTEXEC execution - but only when called from stored procedure 从另一个服务器调用时,存储过程返回不同的结果 - Stored procedure returns different results when called from another server 存储过程在SSMS中运行良好,但是在C#中调用时没有返回行 - Stored Procedure works well in SSMS but no rows returning when it is called in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM