Why CREATE LOGIN failed ?

  • I used dynamic SQL to make a stored procedure to create login :

    USE [db901_DEV]

    GO

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    ALTER PROCEDURE [dbo].[sp_SSSA_login]

    @input_login VARCHAR(50), @input_pass VARCHAR(50)

    AS

    BEGIN

    DECLARE @cmd nvarchar(2000)

    SET @cmd = 'CREATE LOGIN ' + @input_login +' WITH PASSWORD = ' + QUOTENAME(@input_pass,'''')

    + ', DEFAULT_DATABASE= ' + QUOTENAME('db901_DEV','')

    + ', DEFAULT_LANGUAGE= ' + QUOTENAME('us_english','')

    + ', CHECK_EXPIRATION=OFF '

    + ', CHECK_POLICY=OFF '

    Exec sp_executesql @cmd

    END

    If I execute it :

    sp_SSSA_login 'tw.test_901', '7A6b5c'

    It failed.

    If I execute it :

    sp_SSSA_login 'tw_test_901', '7A6b5c'

    It works.

    Could you tell me why ?

  • Replace the CREATE LOGIN statement with the below statement

    SET @cmd = 'CREATE LOGIN [' + @input_login +'] WITH PASSWORD = ' + QUOTENAME(@input_pass,'''')

  • That's great !

    It works. Thanks a lot.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply