存储过程仅在从Management Studio运行时更新

时间:2016-11-08 14:37:29

标签: sql sql-server ssms

所以是的。我有这个非常奇怪的问题。我有以下存储过程

ALTER PROCEDURE [CP24SHOP].[sp_part_set_status_bulk]
    @user                   nvarchar(max),
    @doerTicket             VARCHAR ( 200 ) = null,
    @status                 int,
    @items                  CP24SHOP.udt_parts READONLY
AS
BEGIN
    SET NOCOUNT ON;
        --  Check security
        exec websocket.sp_validate_user
            @user,
            @doerTicket out

        --  foreach row in @items, update the status
        MERGE INTO [file].ItemPart WITH ( XLOCK, ROWLOCK ) AS target 
        USING ( SELECT
                    item.GID        
                FROM @items AS item
             ) AS source
        ON ( target.GID = source.GID )
        WHEN MATCHED THEN
            UPDATE SET
                target.[Status] = @status,
                target.DateTimeModified = GETDATE();

        select 'bob'
    RETURN 0
END

当我使用此代码从Management Studio运行它时

declare @user nvarchar(max) = 'websocket'

        DECLARE @list CP24SHOP.udt_parts
        INSERT INTO @list 
        (
            GID
        )
        VALUES  
        (
            -7228376
        )

        select [Status] from [file].ItemPart
        where GID = -7228376

        exec CP24SHOP.sp_part_set_status_bulk   
            @user = @user,
            @items = @list,
            @status = '155'

        select [Status], DateTimeModified from [file].ItemPart
        where GID = -7228376

它会毫无问题地更新status

但是当通过我们的websocket调用它时,它运行代码并返回" bob"应该如此,但是当我检查数据库时,项目的状态还没有更新。我对可能出错的东西一无所知

1 个答案:

答案 0 :(得分:1)

错误 - 我认为你错过了提交。 在我看来你正在更新&然后回滚!