简体   繁体   English

存储过程成功运行,但从作业中调用时失败

[英]Stored procedure runs successfully but fails when called from a job

I'm running into a very bizarre error in SQL that I would like some help with. 我遇到了一个非常奇怪的SQL错误,希望对此提供帮助。 The code below creates the two stored procedures I need for this report: 下面的代码创建了此报告所需的两个存储过程:

USE [ONDTTEST]

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE ONDT_OPS_OTD_STEP1 
AS
    BEGIN
        SET NOCOUNT ON;

        /** Create Table **/
        CREATE TABLE ONDT_OPS_OTD_SMARTVIEW
        (
            ID      varchar(15) NOT NULL,
            STATUS  char(1) NOT NULL
        );

        /** Insert data into table **/
        INSERT INTO      [ONDT_OPS_OTD_SMARTVIEW]
        SELECT           [ID]
                        ,[STATUS]
        FROM             [CUSTOMER_ORDER]
        WHERE            [STATUS] = 'H';

        /** Update customer order table from H to R **/
        UPDATE           [CUSTOMER_ORDER]
        SET              [STATUS] = 'R'
        WHERE            [STATUS] = 'H';
    END
GO

CREATE PROCEDURE ONDT_OPS_OTD_STEP2 
AS
    BEGIN
        SET NOCOUNT ON;

        /** Update records back to H **/
        UPDATE  [CUSTOMER_ORDER]
        SET     [STATUS] = 'H'
        WHERE   [ID] IN (SELECT [ID] FROM [ONDT_OPS_OTD_SMARTVIEW]);

        /** Drop Table **/
        DROP TABLE ONDT_OPS_OTD_SMARTVIEW;
    END
GO

When I execute both stored procedures it runs succesfully, however when I call the stored procedure from a scheduled job it yields the following error: 当我执行两个存储过程时,它都成功运行,但是当我从计划作业中调用存储过程时,会产生以下错误:

Executed as user: admin. String or binary data would be truncated. [SQLSTATE 22001] (Error 8152)  The statement has been terminated. [SQLSTATE 01000] (Error 3621).  The step failed.

I ran profiler and saw that it fails at the update step to the CUSTOMER_ORDER table on both procedures. 我运行了探查器,发现在两个过程中CUSTOMER_ORDER表的更新步骤中它均失败。 The Status column is set as char(1) and the stored procedure works correctly when called from a query but it is failing when being called from a job. Status列设置为char(1),并且从查询中调用时存储过程可以正常工作,但是从作业中调用时则失败。

Thanks 谢谢

After a lot of struggle I found the culprit. 经过很多努力,我找到了罪魁祸首。 It turns out that SQL does not like the fact that the user name running the job is over 50 characters long. 事实证明,SQL不喜欢运行作业的用户名超过50个字符的事实。 The query works fine when I added: 当我添加时查询工作正常:

EXEC AS USER = 'sysadm' 以用户身份执行='sysadm'

Which is my SQL admin account (same rights as the domain one). 这是我的SQL管理员帐户(与域一具有相同的权限)。 Hopefully this will save someone from the headache it caused me. 希望这可以使某人摆脱我的头痛。

Thanks to everyone who pitched in to help, you guys are great. 谢谢大家的帮助,你们很棒。

Regards, 问候,

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

相关问题 从Service Broker调用时,存储过程失败,但从SSMS运行 - Stored procedure fails when called from Service Broker but runs from SSMS 存储过程失败,但在手动运行时可正常工作 - Stored procedure fails, but works correctly when it runs manually DTSX程序包在Visual Studio中运行,但从数据库作业中调用时不运行 - DTSX package runs in Visual Studio but not when called from a Database Job Postgres pg_notify 不会通知何时从通过 Timescaledb 操作的作业调度程序调用的存储过程更新表 - Postgres pg_notify does not notify when a table gets updated from a stored procedure that is called via the Timescaledb Action's job scheduler 存储过程失败时发出警报 - Alert when stored procedure fails DTEXEC执行时超时-但仅在从存储过程中调用时 - Timeout on DTEXEC execution - but only when called from stored procedure 从另一个服务器调用时,存储过程返回不同的结果 - Stored procedure returns different results when called from another server 从VBA调用时,存储过程中的删除会以静默方式失败 - Deletes in a stored procedure fail silently when called from VBA 当被另一个存储过程调用时,存储过程未返回正确的值 - Stored procedure not returning correct value when called by another stored procedure 调用时存储过程错误 - Stored procedure error when being called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM