0

我在另一个内部调用一个存储过程,由于某种原因,SQL Server 不喜欢我提供的参数。它可能很简单,但我不确定它为什么不喜欢它。

存储过程 1

USE [UserManagerTest]
GO
/****** Object:  StoredProcedure [dbo].[sp_UserManager_Log_User_Off]    Script Date: 11/19/2012 11:33:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================      
-- Author:    Nick Gowdy      
-- Create date: 13-11-2012      
-- Description:  Used by model is UserManager to filter data returned to code          
-- =============================================      
ALTER PROCEDURE [dbo].[sp_UserManager_Log_User_Off] 
                                           @userid           UNIQUEIDENTIFIER

AS 
  BEGIN 

 -- Get SessionID from UserID
 DECLARE @sessionid VARCHAR(60)
 DECLARE @userid uniqueidentifier
 select @userid = '61B08729-BB4F-426C-B20B-697F40F458C5'

 EXEC @sessionid = aspnet_Membership_Custom_GetUserSessionsByUserId @userid
 select @sessionid as sessionid

 -- Delete user session based on sessionid and userid
 EXEC aspnet_Membership_Custom_DeleteUserSession @sessionid, @userid
 END    

存储过程 2

USE [UserManagerTest]
GO
/****** Object:  StoredProcedure [dbo].[aspnet_Membership_Custom_GetUserSessionsByUserId]    Script Date: 11/19/2012 12:16:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE [dbo].[aspnet_Membership_Custom_GetUserSessionsByUserId]
    @UserId      uniqueidentifier
AS
BEGIN

declare @SessionId varchar(60)
select @SessionId = ( SELECT    
        [UserId]
    FROM    
        [dbo].[aspnet_Custom_UserSessionActivity]
    WHERE   
        [UserId] = @UserId)

        --select @SessionId

RETURN @SessionId
end

当我执行 sp_usermanager_log_user_off 时出现此错误

Msg 245, Level 16, State 1, Procedure aspnet_Membership_Custom_GetUserSessionsByUserId, Line 17
Conversion failed when converting the varchar value '61B08729-BB4F-426C-B20B-697F40F458C5' to data type int.

有任何想法吗?谢谢!

4

2 回答 2

2

我最好的猜测是,当您实际上想要一个功能时,您定义了一个过程。

存储过程返回一个 int,即错误代码。您正在尝试返回其他内容(即唯一标识符)并且它不起作用。

您还可以修改您的过程以提供 OUTPUT 参数。

MSDN 文档(http://msdn.microsoft.com/en-us/library/ms187926.aspx):

将状态值返回给调用过程或批处理以指示成功或失败(以及失败的原因)。

于 2012-11-19T15:25:46.687 回答
0

使用 long 或 float - 该字符串可能太大而无法转换为整数值

于 2012-11-19T15:19:59.743 回答