locked
The server principal 'username' already exists (Microsoft SQL Server, error: 15025) RRS feed

  • Question

  • SQL Management Studio

    SQL 2008 R2

    Create database

    Restor from backup

    Now I am trying to create login

    I get an error The server principal 'username' already exists (Microsoft SQL Server, error: 15025)

    I delete user from database and try to create user having same error


    Muhammad Mehdi

    Tuesday, June 18, 2013 1:33 AM

Answers

  • Hi Muhammed,

    Please go through the below steps,

    
    
    use master 
    go
    drop login <yourloginname>
    go
    create login <yourloginname> with password='yourpassword',<requiredoptions>
    go

    for the various option available with create login pls refer :

    http://msdn.microsoft.com/en-us/library/ms189751.aspx

    If the login is already there, you can try to fix the orphan users in DB instead of deleting the login.

     you can use

    alter user username with login=loginname

    please refer alter user syntax here

    http://msdn.microsoft.com/en-us/library/ms176060.aspx

    or

    You can make use of  sp_change_users_login which is deprecated to fix the orphan user issue after restoring Db from one server to another server.

    After fixing the orphan users issue your login in the new server will be able to connect to the restored DB with all the permissions as in the old server.

    But if you have already deleted the users in the DB, then you have to create the user for the login.

    Thanks


    • Edited by udhayan Tuesday, June 18, 2013 8:47 AM
    • Marked as answer by Fanny Liu Saturday, June 22, 2013 9:38 AM
    Tuesday, June 18, 2013 8:43 AM

All replies

  • Now I am trying to create login

    I get an error The server principal 'username' already exists (Microsoft SQL Server, error: 15025)

    I delete user from database and try to create user having same error


    Muhammad Mehdi

    Have you deleted login( but you have deleted User from database) and try to create then? 

    http://blog.sqlauthority.com/2007/02/15/sql-server-fix-error-15023-user-already-exists-in-current-database/

    http://blogs.msdn.com/b/sqlserverfaq/archive/2010/04/06/unable-to-create-a-login-in-sql-server-2005-and-we-get-the-following-error-the-server-principal-domain-machine-account-already-exists.aspx


    Srinivasan

    Tuesday, June 18, 2013 3:39 AM
  • I get an error The server principal 'username' already exists (Microsoft SQL Server, error: 15025)

    I delete user from database and try to create user having same error

    Hello Muhammad,

    That's the "database principal" which you deleted, but the "server principal" (= server login) still exists and you can't add it a second time, therefore you get the error message.

    And because it still exists, there is no need to add it again.


    Olaf Helper

    Blog Xing


    Tuesday, June 18, 2013 7:03 AM
  • Hi Muhammed,

    Please go through the below steps,

    
    
    use master 
    go
    drop login <yourloginname>
    go
    create login <yourloginname> with password='yourpassword',<requiredoptions>
    go

    for the various option available with create login pls refer :

    http://msdn.microsoft.com/en-us/library/ms189751.aspx

    If the login is already there, you can try to fix the orphan users in DB instead of deleting the login.

     you can use

    alter user username with login=loginname

    please refer alter user syntax here

    http://msdn.microsoft.com/en-us/library/ms176060.aspx

    or

    You can make use of  sp_change_users_login which is deprecated to fix the orphan user issue after restoring Db from one server to another server.

    After fixing the orphan users issue your login in the new server will be able to connect to the restored DB with all the permissions as in the old server.

    But if you have already deleted the users in the DB, then you have to create the user for the login.

    Thanks


    • Edited by udhayan Tuesday, June 18, 2013 8:47 AM
    • Marked as answer by Fanny Liu Saturday, June 22, 2013 9:38 AM
    Tuesday, June 18, 2013 8:43 AM
  • Thanks for the help. 
    • Proposed as answer by RCirino Thursday, November 27, 2014 4:38 PM
    Thursday, November 27, 2014 4:38 PM
  • It over half way through 2019 and we still have to fix orphans this way.
    Thursday, August 8, 2019 11:12 AM
  • Hi,

    you can fix your orphaned user with this script.

    Use it in the database context.

    -- just take a look for orphaned users
    EXEC sp_change_users_login 'Report'
    
    -- fix the orphaned users
    EXEC sp_change_users_login 'Auto_Fix', 'just_replace_me'


    There is no need to drop / create users for that.

    Kind regards,

    Andreas

    Friday, August 9, 2019 8:58 AM