SQL Server Performance

When adding sql server logins ,its failing with below error?

Discussion in 'SQL Server 2005 General DBA Questions' started by mssql_dba_123, Apr 1, 2009.

  1. mssql_dba_123 New Member

    The server principal 'logins_name'already exists.
    when check login and user for database there is no user with the same name.
    Pleae help
  2. rohit2900 Member

    hi,
    run below querySELECT
    * FROM MASTER.dbo.SYSLOGINSWHERE
    NAME = your_login_name
    As per the error you are getting this will return one row and this means the login already existing.
    FYI: Logins are created at instance level and then we can assign them different db access.
    Try sp_adduser
    http://msdn.microsoft.com/en-us/library/aa259596(SQL.80).aspx
  3. satya Moderator

    As referred by ROhit you could use SP_ADDUSER, but a note from BOL: This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use /msdn.microsoft.com/mshelp" />CREATE USER instead.To avoid the main issue of the error you could try the following:IF NOT EXISTS(SELECT name FROM sys.server_principals WHERE name = 'test_user')BEGIN CREATE LOGIN test_user WITH PASSWORD = 'Password'END
    OR
    IF NOT EXISTS(SELECT name FROM sys.sql_logins WHERE name = 'username')BEGIN CREATE LOGIN test_user WITH PASSWORD = 'Password'END

Share This Page