2016-05-03 89 views
0

這是我做的:爲什麼這看起來像我的程序?

use FCT; 
declare @CORREO varchar(80) 
declare @SALT varchar(100) 
declare @PASS varchar(100) 
declare @PASSWORDECRYPT VARCHAR(100) 
declare @Nuevo INT 
set @CORREO = '[email protected]' 
set @PASS = 'xyz123%' 
set @Nuevo = 1 
exec PROC_RegistroUsuario @CORREO, @SALT, @PASS, @PASSWORDECRYPT, @Nuevo 

執行此出現後:

(1行(S)的影響)

消息515,級別16,狀態2,過程PROC_RegistroUsuario,第58行 無法將值NULL插入到'Password'列中'Facturas.dbo.aspnet_Membership'表;列不允許有空值。 INSERT失敗。 該聲明已被終止。

(1行(S)的影響)

(1行(S)的影響)

這是我的存儲過程:

USE [FCT] 
GO 

SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 

CREATE PROCEDURE [dbo].[PROC_RegistroUsuario] @CORREO VARCHAR(80), @SALT VARCHAR(100), @PASS VARCHAR(100), @PASSWORDECRYPT VARCHAR(100), @Nuevo INT 
AS 
BEGIN 

DECLARE @USERID UNIQUEIDENTIFIER, 
     @MensajeRegreso VARCHAR(8000), 
     @CantidadContactosEmpresa INT, 
     @EmpresaRFC char(13) 

SET @USERID = (SELECT [UserId] FROM [dbo].[aspnet_Users] WHERE [UserName] = @CORREO) 

IF @Nuevo IN (1, 2) 
BEGIN 
    SET @CantidadContactosEmpresa = (SELECT COUNT(*) FROM [dbo].[EmpresaUser] WHERE [EmpresaUser_Empresa] IN (SELECT [EmpresaUser_Empresa] FROM [dbo].[EmpresaUser] WHERE [EmpresaUser_Email] = @CORREO)) 
    IF @USERID IS NULL 
    BEGIN 
     INSERT INTO dbo.aspnet_Users 
        (ApplicationId , 
         UserId , 
         UserName , 
         LoweredUserName , 
         MobileAlias , 
         IsAnonymous , 
         LastActivityDate 
        ) 
      SELECT TOP 1 ApplicationId , -- ApplicationId - uniqueidentifier 
         NEWID() , -- UserId - uniqueidentifier 
         @CORREO , -- UserName - nvarchar(256) 
         LOWER(@CORREO) , -- LoweredUserName - nvarchar(256) 
         NULL , -- MobileAlias - nvarchar(16) 
         0 , -- IsAnonymous - bit 
         GETDATE() -- LastActivityDate - datetime 
        FROM dbo.aspnet_Applications 

      SET @USERID = (SELECT UserId FROM dbo.aspnet_Users WHERE UserName = @CORREO) 

      INSERT INTO dbo.aspnet_Membership 
        (ApplicationId , 
         UserId , 
         Password , 
         PasswordFormat , 
         PasswordSalt , 
         MobilePIN , 
         Email , 
         LoweredEmail , 
         PasswordQuestion , 
         PasswordAnswer , 
         IsApproved , 
         IsLockedOut , 
         CreateDate , 
         LastLoginDate , 
         LastPasswordChangedDate , 
         LastLockoutDate , 
         FailedPasswordAttemptCount , 
         FailedPasswordAttemptWindowStart , 
         FailedPasswordAnswerAttemptCount , 
         FailedPasswordAnswerAttemptWindowStart , 
         Comment 
        ) 
      SELECT ApplicationId , -- ApplicationId - uniqueidentifier 
         @USERID , -- UserId - uniqueidentifier 
         @PASSWORDECRYPT , -- Password - nvarchar(128) 
         1 , -- PasswordFormat - int 
         @SALT , -- PasswordSalt - nvarchar(128) 
         NULL , -- MobilePIN - nvarchar(16) 
         @CORREO , -- Email - nvarchar(256) 
         LOWER(@CORREO) , -- LoweredEmail - nvarchar(256) 
         'Pregunta' , -- PasswordQuestion - nvarchar(256) 
         @PASSWORDECRYPT , -- PasswordAnswer - nvarchar(128) 
         1 , -- IsApproved - bit 
         0 , -- IsLockedOut - bit 
         GETDATE() , -- CreateDate - datetime 
         GETDATE() , -- LastLoginDate - datetime 
         GETDATE() , -- LastPasswordChangedDate - datetime 
         '18990101' , -- LastLockoutDate - datetime 
         0 , -- FailedPasswordAttemptCount - int 
         '18990101' , -- FailedPasswordAttemptWindowStart - datetime 
         0 , -- FailedPasswordAnswerAttemptCount - int 
         '18990101', -- FailedPasswordAnswerAttemptWindowStart - datetime 
         @PASS -- Comment - ntext 
        FROM dbo.[aspnet_Applications] 

     /*Empresas*/ 

     INSERT INTO dbo.aspnet_UsersInRoles 
        (UserId, RoleId) 
      SELECT @USERID, -- UserId - uniqueidentifier 
         RoleId -- RoleId - uniqueidentifier 
        FROM dbo.aspnet_Roles WHERE RoleName IN ('Empresas') 
    END 

    ELSE 

    BEGIN 

     SET @PASS = (SELECT TOP 1 [EmpresaUser_Password] FROM [dbo].[EmpresaUser] WHERE [EmpresaUser_Email] = @CORREO ORDER BY [EmpresaUser_Email]) 

     UPDATE [dbo].[EmpresaUser] SET [EmpresaUser_Password] = @PASS WHERE [EmpresaUser_Email] = @CORREO 

     SET @MensajeRegreso = 'El usuario ya existe dentro de la base de datos, se agregó la cuenta a esta empresa, el podrá ingresar con su antigua contraseña.' 
    END 
END 

ELSE 

BEGIN 
    DECLARE @EnPerfil BIT 

    IF (SELECT COUNT(*) FROM [dbo].[aspnet_UsersInRoles] WHERE [UserId] = @USERID AND [RoleId] = (SELECT [UserId] FROM [dbo].[aspnet_Roles] WHERE [RoleName] = 'Empresas')) = 0 
    BEGIN 
     SET @EnPerfil = 0 
    END 

    ELSE 

    BEGIN 
     SET @EnPerfil = 1 
     SET @MensajeRegreso = 'El usuario ya cuenta con un perfil, no se puede cambiar la contraseña.' 
    END 

    IF @EnPerfil = 0 
    BEGIN 
     UPDATE [dbo].[aspnet_Membership] SET [Password] = @PASSWORDECRYPT WHERE [UserId] = @USERID 
     SET @MensajeRegreso = 'Datos contacto actualizados.' 
    END 
END 

IF @Nuevo IN (0, 1) 
BEGIN 
    SELECT @MensajeRegreso AS Mensaje 
END 
END 

回答

1

你不設置@PASSWORDECRYPT在執行存儲過程之前,它的值仍然是NULL

相關問題